-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
717.cpp
38 lines (38 loc) · 977 Bytes
/
717.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int i=0;
if(bits.size()==1&&bits[0]==0) return true;
while(i<bits.size())
{if(bits[i]==0)
++i;
else i+=2;
if(i==bits.size()-1) return true;
}
return false;
}
};
__________________________________________________________________________________________________
sample 8944 kb submission
class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
if(bits.size() == 1 || bits[bits.size()-2] == 0){
return true;
}
for(int i = 0; i != bits.size();){
if(bits[i] == 1){
i += 2;
}else{
i++;
}
if(i == bits.size()-1){
return true;
}
}
return false;
}
};
__________________________________________________________________________________________________