717. 1-bit and 2-bit Characters
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 45% Topics: Array
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# 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
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions