We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。
Input: [1,2,3,null,5,null,4] Output: [1, 3, 4] Explanation: 1 <--- / \ 2 3 <--- \ \ 5 4 <---
The text was updated successfully, but these errors were encountered:
/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } */ /** * @param {TreeNode} root * @return {number[]} */ var rightSideView = function(root) { if (root === null) { return []; } const queue = [[root, 0]]; const result = []; while (queue.length !== 0) { const [node, depth] = queue.shift(); result[depth] = node.val; if (node.left) { queue.push([node.left, depth + 1]); } if (node.right) { queue.push([node.right, depth + 1]); } } return result; };
Sorry, something went wrong.
No branches or pull requests
199. Binary Tree Right Side View
给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。
Example
The text was updated successfully, but these errors were encountered: