#1104

Path In Zigzag Labelled Binary Tree

pupil · 505 · lc medium +27 · verified · 75.8% accepted · 1,546 likes · top 87%

Description

Consider an infinite binary tree where nodes are labeled row by row. Odd-numbered rows (1st, 3rd, 5th, ...) are labeled left to right; even-numbered rows are labeled right to left.

Given the label of a node, return the sequence of labels along the path from the root to that node.

Example 1:

Input: label = 14
Output: [1,3,4,14]

Example 2:

Input: label = 26
Output: [1,2,6,10,26]

Code

1
2
3