You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In an infinite binary tree where every node has two children, the nodes are labelled in row order.
In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.
Given the label of a node in this tree, return the labels in the path from the root of the tree to the node with that label.
In an infinite binary tree where every node has two children, the nodes are labelled in row order.
In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.

Given the label of a node in this tree, return the labels in the path from the root of the tree to the node with that label.
Example 1:
Example 2:
Constraints:
解法:
这道题看着挺唬人,其实就是找规律。很显然,如果不论什么正序反序,根据完全二叉树的规则,可以根据子节点算出父节点。
比如示例一,根据14,可以算出到达他的路径是[1, 3, 7, 14],无非就是一直除2。与答案不用就在于加了个正序反序,怎么根据7
算4,很简单,可以看出在第三层,每一个对应位置的结点,都有规律,4对应7,5对应6,他们的和是一定,所以只要算出这个和,再减7,就是4了。
代码如下:
The text was updated successfully, but these errors were encountered: