class Solution:
def isOneBitCharacter(self, bits: List[int]) -> bool:
"""tc O(N) sc(N)
"""
start = 0
end = len(bits) -1
def dfs(s,e):
if s > e :
return True
if bits[s] == 0:
return True and dfs(s+1,e)
elif e-s >1 and bits[s] == 1:
return True and dfs(s+2,e)
return False
return dfs(start,end)
optimization
class Solution:
def isOneBitCharacter(self, bits: List[int]) -> bool:
"""tc O(N) sc(1)
to distinguish 2 bits or 1 bit is first bit if its 1 or 0 => i as a ptr to jump 1 step or 2 step based on its value
1. go through bits [:-1]
2. keep increment i by at least 1 as well as i's current val
3. if i arrive right at n-1 position means last bits size is 1
"""
i = 0
n = len(bits)
while i < n-1:
i += bits[i]+1
return i == n-1