观察发现对于每个node如果它在vertical level k上那它的左子树在level k-1, 右子树k+1. level order traverse的同时,多记录一栏track vertical order就好。 每个level用map来装,这样输出的时候自动按从左到右排好了。 面经:print the top view of a binary tree 实现:Time O(nlogn) BFS-n, map-logn Space...
英文网站:199. Binary Tree Right Side View 中文网站:199. 二叉树的右视图 问题描述 Given therootof a binary tree, imagine yourself standing on theright sideof it, returnthe values of the nodes you can see ordered from top to bottom. Example 1: Input: root = [1,2,3,null,5,null,4] O...
今天和大家聊的问题叫做 二叉树的右视图,我们先来看题面: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. 题意 给定一...
LeetCode OJ: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. For example: Given the following binary tree, 1 <--- / \ 2 3 <--- \ \ 5 4...
4、层序遍历树的右视图:Binary Tree Right Side View - LeetCode 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: [1, 3, 4]Explanation: 1 <--...
【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,...
topcpper / LeetCodeAnimation tsuliuchao / LeetCodeAnimation tuan28064 / LeetCodeAnimation turbo73 / LeetCodeAnimation twistedmove / LeetCodeAnimation twlkyao / LeetCodeAnimation ty01csbaidu / LeetCodeAnimation Tyeeee / LeetCodeAnimation u5207541 / LeetCodeAnimation UnderTreeTech / Leet...
1343 Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold 68.10% Medium 1342 Number of Steps to Reduce a Number to Zero 84.90% Easy 1341 Movie Rating * 43.80% Medium 1340 Jump Game V 62.60% Hard 1339 Maximum Product of Splitted Binary Tree 47.70% Medium 1338 Re...
LeetCode 刷题随手记 - 第一部分 前 256 题(非会员),仅算法题,的吐槽 https://leetcode.com/problemset/algorithms/...
199. Binary Tree Right Side View (给一棵二叉树,想像你站在右边看这课树,返回你从头结点到尾结点所能看到的所有结点的值)class Solution { public: queue<TreeNode*> q1; vector<int> res; void help(){ while(!q1.empty()){ int size = q1.size(); for(int i=0;i<size;i++){ TreeNode* ...