1-bit and 2-bit Characters LeetCode solution in C++

1
class Solution {
2
public:
3
bool isOneBitCharacter(vector<int> &bits) {
4
int n = bits.size();
5
if (n == 1) return true;
6

7
int i = 0;
8
while (i <= n - 2) {
9
if (bits[i] == 0)
10
i++;
11
else
12
i = i + 2;
13
}
14
if (i <= n - 1)
15
return true;
16
else
17
return false;
18
}
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0