Path in ZigZag Tree
https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/
class Solution:
def pathInZigZagTree(self, label: int) -> List[int]:
curr =1
res = []
while curr <= label:
curr *=2
nxt = label
while nxt != 1:
currMax = curr-1
currMin = curr//2
res.append(nxt)
nxt = (currMax+currMin- nxt)//2
curr//=2
res.append(nxt)
return res[::-1]
Last updated