Recursive, Recursive, Recursive...🤮
class Solution:
def kthGrammar(self, N: int, K: int) -> int:
if N == 1:
return 0
elif N == 2:
return 0 if K == 1 else 1
v = self.kthGrammar(N - 1, (K + 1) // 2)
if v == 0:
if K % 2 == 0:
return 1
else:
return 0
else:
if K % 2 == 0:
return 0
else:
return 1
Top comments (0)