← 返回 amazon 的题目列表Path In Zigzag Labelled Sequence
类型:online_judge
Given a peculiar sequence which consists of [1, 2, 3, ..., n], interpret it as a complete binary tree where odd-numbered depths (levels) are labelled from left to right and even-numbered depths are labelled from right to left. Given a label, return the path from the root to the given label.
Example 1:
n = 14, label = 14
Output: [1, 3, 4, 14]
Conditions:
Integer 1 <= label <= (2^h - 1), h is the height of the tree
0 <= h <= 1000
Example
Input
14