代码如下: 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()...
* Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { private int maxDepth=0; public List<Integer> rightSideView(TreeNode root) { //require List<Integer> a...
1/**2* Definition for a binary tree node.3* struct TreeNode {4* int val;5* TreeNode *left;6* TreeNode *right;7* TreeNode(int x) : val(x), left(NULL), right(NULL) {}8* };9*/10classSolution {11public:12vector<int> rightSideView(TreeNode*root) {13intdep = -1;14bfs(roo...
每次先将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...
参考LeetCode #102 Binary Tree Level Order Traversal 二叉树的层序遍历 层次遍历按层输出最右边的结点 时间复杂度O(n), 空间复杂度O(n) 代码: C++: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...
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 <--- / \ ...
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 { ...
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,
【leetcode】Binary Tree Right Side View(middle) 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,...
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 ...