Easy
1-bit and 2-bit Characters — Python
Full explanation · Time O(n) · Space O(1)
# Time: O(n)
# Space: O(1)
class Solution(object):
def isOneBitCharacter(self, bits):
"""
:type bits: List[int]
:rtype: bool
"""
parity = 0
for i in reversed(xrange(len(bits)-1)):
if bits[i] == 0:
break
parity ^= bits[i]
return parity == 0