代码如下: 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 therightside 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 <--- \ \ 5 4 <--- 给一个二叉树,想象你...
LeetCode 199. Binary Tree Right Side View Given the root of 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 1: Input: root = [1,2,3,null,5,null,4] Output: [1,3,4] Example 2:...
* TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution{public:vector<int>rightSideView(TreeNode*root){vector<int>result;if(!root)returnresult;queue<TreeNode*>q;q.push(root);while(q.size()){ints=q.size();result.push_back(q.front()...
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 <—
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...
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 <--- ...
[LeetCode] 199. 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. Example: 代码解读 Input: [1,2,3,null,5,null,4]...
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...
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.LeetCode199. Bi...