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]. 本题难度...
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...
代码如下: 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()...
* TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };*/classSolution {public: vector<int> rightSideView(TreeNode *root) { vector<int>res;if(!root)returnres; queue<TreeNode*>q; q.push(root);while(!q.empty()) { res.push_back(q.back()->val);i...
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 <--- / \ ...
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. BFS Time Complexity O(N) Space Complexity O(N) 思路 用传统的BFS,唯一要加的是(i == size - 1)的时候,注意是size...
199 Binary Tree Right Side Viewhttps://leetcode-cn.com/problems/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...
LeetCode 每日一题 Daily Challenge 983 Minimum Cost For Tickets 102 -- 3:56 App LeetCode 每日一题 Daily Challenge 199 Binary Tree Right Side View 84 -- 5:48 App LeetCode 每日一题 Daily Challenge 1032 Stream of Characters 90 -- 1:45 App LeetCode 每日一题 Daily Challenge 100 Same 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,...