Leetcode 717. 1 bit and 2 bit Characters

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

1-bit and 2-bit Characters

2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int step = 1;
int index = 0;
while(index < bits.size()) {
step = bits[index]==1?2:1;
index += step;
}
return step == 1;
}
};

Reference

  1. https://leetcode.com/problems/1-bit-and-2-bit-characters/description/
如果有收获,可以请我喝杯咖啡!