1-bit and 2-bit Characters

easy array

Problem

Decide if the last character of bits (which ends in 0) is a 1-bit (0) char.

Inputbits = [1,0,0]
OutputTrue
Parsing left to right: '10' then '0' — last is the 1-bit char.

def is_one_bit_character(bits):
    i = 0
    while i < len(bits) - 1:
        i += 2 if bits[i] == 1 else 1
    return i == len(bits) - 1
function isOneBitCharacter(bits) {
  let i = 0;
  while (i < bits.length - 1) i += bits[i] === 1 ? 2 : 1;
  return i === bits.length - 1;
}
boolean isOneBitCharacter(int[] bits) {
    int i = 0;
    while (i < bits.length - 1) i += bits[i] == 1 ? 2 : 1;
    return i == bits.length - 1;
}
bool isOneBitCharacter(vector& bits) {
    int i = 0;
    while (i < (int)bits.size() - 1) i += bits[i] == 1 ? 2 : 1;
    return i == bits.size() - 1;
}
Time: O(n) Space: O(1)