199 Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
For example: Given the following binary tree,
1 <— / / 2 3 <— / / 5 4 <—
You should return [1, 3, 4].
Credits: Special thanks to @amrsaqr for adding this PRoblem and creating all test cases. 題目原文
從上到下寫出二叉樹每層最右側節點對應的數值
按層次遞歸,并將層數作為遞歸變量使每層只記錄一個數值,從右至左遍歷則使每層右邊節點最先遍歷,該節點數值即可在本層唯一記錄。
新聞熱點
疑難解答