#717
1-bit and 2-bit Characters
pupil · 515 · lc easy +28 · verified · 49.5% accepted · 1,246 likes · top 36%
Description
Two special encoded characters exist:
- A one-bit character is encoded as a single 0.
- A two-bit character is encoded as 10 or 11.
You are given a binary array bits whose final element is 0. Determine whether the last character in a valid decoding of bits must be the one-bit character; return true if so, false otherwise.
Example 1:
Input: bits = [1,0,0]
Output: true
Explanation: The only way to decode it is two-bit character and one-bit character.
So the last character is one-bit character.
Example 2:
Input: bits = [1,1,1,0]
Output: false
Explanation: The only way to decode it is two-bit character and two-bit character.
So the last character is not one-bit character.
Code
1
2
3