private void rightSideViewHelper(TreeNode node, List<Integer> result, int level){ if(node == null) return; if(result.size() == level){ result.add(node.val); } rightSideViewHelper(node.right, result, level+1); rightSideViewHelper(node.left, result, level+1); } }
问题链接 英文网站:199. Binary Tree Right Side View中文网站:199. 二叉树的右视图问题描述Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the n…
Top view, Bot view, right view, and left view. 1/**2* Definition for binary tree3* public class TreeNode {4* int val;5* TreeNode left;6* TreeNode right;7* TreeNode(int x) { val = x; }8* }9*/10publicclassSolution {11publicList<Integer>rightSideView(TreeNode root) {12List<...
Binary Tree Right Side View Given a binary tree, imagine yourself standing on therightside 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,...
Binary Tree Right Side View Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the following binary tree, 1 <--- / \
//Definition for binary tree struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution { public: vector<int> rightSideView(TreeNode *root) { if(root==NULL) ...
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 <--- / \ ...
1privatevoiddfsHelper(Map<Integer,Integer>depthToValue,TreeNode node,int depth){2if(node==null){3return;4}56// this is a pre-order traversal, essentially keep overwriting the depthToValue map (right view)7// while traverse the tree from left to right8depthToValue.put(depth,node.val);9...
199. Binary Tree Right Side View** 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. Example: Input: [1,2,3,null,5,null,4]Output: [1, 3, 4]Explanation: 1 <--- / \2 3 <--- \...
SysTypeIdView TableAccess TableCollectionList TableRelation TabPageStyle TabStyle TextBuffer TextIo ThousandSeparator TileReference TimeFormat TimeSeparator Timezone TimeZonePreference TimeZonesList TimeZonesRulesData ToggleButtonStyle TreeNode TreeNodeIterator TreeNodeType Uncheck UnitofWork Units UserAccountType ...