问题链接 英文网站: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. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // 黄哥Python培训 黄哥所写 func rightSideView(root *TreeNode) []int { if root == nil { return []int{} } var res []int queue := [][]interface{}{{root,...
* 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);intsize =q.size();f...
1、题目描述 2、问题分析 使用层序遍历 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();13...
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 <--- / \ ...
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); ...
Problem Statement 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: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 Input:[1,2,3,null,5,null,4]Output:[1,3,4]Explanation:1<---/\23...
Binary Tree Right Side View 好久没有刷leetcode了,要继续了。。 今天第一题。 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:
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 { ...
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, 1 <--- / \ 2 3 <--- \ \ 5 4 <--- ...