代码如下: publicList<Integer>rightSideView(TreeNoderoot){LinkedList<Integer>result=newLinkedList<>();if(Objects.isNull(root)){returnresult;}LinkedList<TreeNode>levelA=newLinkedList<>(),levelB=newLinkedList<>();levelA.addFirst(root);while(!levelA.isEmpty()){TreeNodetreeNode=levelA.removeLast()...
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]. 本题难度...
使用层序遍历 3、代码 1vector<int>v;2vector<int> rightSideView(TreeNode*root) {3if(root ==NULL)4returnv;56queue<TreeNode*>q;7q.push(root);89while(!q.empty()) {10intsize =q.size();11for(inti =0; i < size; i++) {12TreeNode *node =q.front();13if(node->left !=NULL)1...
每次先将right side node 加入到queue里去 保证 当i = 0 的时候,poll出来的第一个item是right side node 代码 1 public List<Integer>rightSideView(TreeNode root) { 2 // level order traversal 3 List<Integer> result = newArrayList(); 4 Queue<TreeNode> queue = newLinkedList(); 5 // corner c...
199 Binary Tree Right Side View 二叉树的右视图 Description: 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. Example: Input: [1,2,3,null,5,null,4] ...
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 <--- / \ ...
Leetcode 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,
http://www.programcreek.com/2014/04/leetcode-binary-tree-right-side-view-java/ 看了这篇博客就懂了。 ** 总结: queue来遍历tree ** Anyway, Good luck, Richardo! My code: /** * Definition for a binary tree node. * public class TreeNode { ...
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. Example: Input:[1,2,3,null,5,null,4]Output:[1,3,4]Explanation:1<---/\23<---\ \54<---...
Leetcode solution 199:Binary Tree Right Side View Blogger:https://blog.baozitraining.org/2019/10/leetcode-solution-199-binary-tree-right.html Youtube:https://youtu.be/_g6pN64bF-o 博客园: https://www.cnblogs.com/baozitraining/p/11595617.html ...