问题链接 英文网站: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
Python: Compute the right view of both right and left left subtree, then combine them. For very unbalanced trees, this can be O(n^2), though. 1 2 3 4 5 6 defrightSideView(self, root): ifnotroot: return[] right=self.rightSideView(root.right) left=self.rightSideView(root.left) r...
* Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * 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<Tree...
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # 黄哥Python培训 黄哥所写 class Solution: def rightSideView(self, root: TreeNode) -> List[int]: if root is None: return [] res = [...
今天和大家聊的问题叫做 二叉树的右视图,我们先来看题面:https://leetcode-cn.com/problems/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. ...
5 * TreeNode *left; 6 * TreeNode *right; 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>(); ...
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 <--- / \ ...
if(curr.right!=null) s.push(curr.right); if(curr.left!=null) s.push(curr.left); } return res; } } Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, ...
* Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */classSolution{public:TreeNode*invertTree(TreeNode*root){if(!root)returnroot;swap(root->right,root->left...
一. 树 1)求二叉树的高度(Maximum Depth of Binary Tree)// LeetCode, Maximum Depth of Binary ...