717. 1-bit and 2-bit Characters

T: O(n)
S: O(1)
```java
class Solution {
    public boolean isOneBitCharacter(int[] bits) {
        int ones = 0;
        for (int i = bits.length - 2; i >= 0; i--) {
            if (bits[i] != 0) {
                ones++;
            } else {
                break;
            }
        }
        return ones % 2 == 0; // if even -> true
    }
}

/**

T: O(n)
S: O(1)

...00 true
...10 false
..110 true
.1110.false
11110 true 



so if odd one (in the end, between 2 zero, because 0 can be solve by one digit) -> it's false

like this, we only care about -> 11110
00011110
 */
```

Last updated