-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
717.java
44 lines (40 loc) · 1.38 KB
/
717.java
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
39
40
41
42
43
44
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public boolean isOneBitCharacter(int[] bits) {
int ones = 0;
//Starting from one but last, as last one is always 0.
for (int i = bits.length - 2; i >= 0 && bits[i] != 0 ; i--) {
ones++;
}
if (ones % 2 > 0) return false;
return true;
}
}
__________________________________________________________________________________________________
sample 37208 kb submission
class Solution {
public boolean isOneBitCharacter(int[] bits) {
int twoCharsStatus = 0;
for(int i = 0; i < bits.length; i++) {
if(bits[i] == 1) {
// if(bits.length % 2 == 1)
// return true;
if(twoCharsStatus != 1)
twoCharsStatus = 1;
else
twoCharsStatus = 2;
} else {
if(twoCharsStatus == 1)
twoCharsStatus = 2;
else {
twoCharsStatus = 0;
}
}
}
if(twoCharsStatus == 0)
return true;
return false;
}
}
__________________________________________________________________________________________________