We have two special characters: the first character can be represented by one bit 0, and the second character can be represented by two bits (10 or 11). Given a binary array bits that ends with 0, return true if the last character must be a one-bit character.
We have two special characters: the first character can be represented by one bit 0, and the second character can be represented by two bits (10 or 11). Given a binary array bits that ends with 0, return true if the last character must be a one-bit character.
Example 1:
Input: {"bits":[1,0,0]}
Output: true
Constraints:
1≤bits.length≤1000
bits[i] is either 0 or 1.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"bits":[1,0,0]}
Start decoding at i = 0. A 0 is a whole character; a 1 always starts a two-bit character, so it swallows the next bit.