问题链接 英文网站: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 nodes you can see ordered from top
* Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} ...
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };*/structNode { TreeNode*tnode;intlevel; Node(TreeNode* t,intl): tnode(t), level(l) {} };classSolution {public: vector<int> rightSideView(TreeNode *root) { vector<int>ret;if(root ==NULL)returnret; queue<Node*...
classSolution{public:vector<int>rightSideView(TreeNode* root){ vector<int> res;if(!root)returnres; queue<TreeNode*> q; q.push(root);while(q.size()) {intsize = q.size();while(size--) {//先判断进入后马上-1autot = q.front(); q.pop();if(!t)continue;//判断空节点if(size==0)...
* Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} ...
/** * Definition for a binary tree node. * 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) { auto ret =...
https://leetcode-cn.com/problems/binary-tree-right-side-view/ 【题目】 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 代码语言:javascript 代码运行次数:0 示例:输入:[1,2,3,null,5,null,4]输出:[1,3,4]解释:1<---/\23<---\ \54<--- ...
4 199E - 二叉树的右视图Binary Tree Right Side View 思路: 所谓右视图,是指从右边看过来能看到的全部节点列表,从根节点往下; 对于一个空节点,那么就不做任何操作;这也是递归函数结束的条件; 从右子树开始(再到左子树),用高度和记录右视图节点的列表长度进行对比,如果相等,那么将该节点的元素 append 进右视...
7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution { 11 public: 12 vector<int> rightSideView(TreeNode* root) { 13 if(root==NULL) return vector<int>(); 14 deque<TreeNode*> que(1,root); ...
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 <--- / \ ...