[leetcode] Binary Tree Right Side View
dfs,記錄已經訪問到的層數即可。程式碼如下:
vector<int> rightSideView(TreeNode *root) { vector<int> result; int curLevel = 0, level = -1; dfs(result, curLevel, level, root); return result; } void dfs(vector<int> &result, int curLevel, int &level, TreeNode *root){ if(!root) return; if(curLevel > level){ result.push_back(root->val); ++level; } dfs(result, curLevel + 1, level, root->right); dfs(result, curLevel + 1, level, root->left); }
相關推薦
LeetCode-Binary Tree Right Side View
一、Description Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered
[LeetCode] 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 examp
[leetcode] Binary Tree Right Side View
dfs,記錄已經訪問到的層數即可。程式碼如下: vector<int> rightSideView(TreeNode *root) { vector<int> result; int curLevel = 0, lev
LeetCode Binary Tree Right Side View
層次遍歷 我的想法:層序遍歷,然後輸出每一層最右邊的節點程式碼如下: class Solution { public: vector<int> rightSideView(TreeNode* root) { vector<int&g
LeetCode 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 t
[LeetCode] 199. Binary Tree Right Side View
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 o
[leetcode]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. E
[leetcode]199. Binary Tree Right Side View
[leetcode]199. Binary Tree Right Side View Analysis 好冷鴨—— [每天刷題並不難0.0] Given a binary tree, imagine yourself standing on the right
LeetCode 199.Binary Tree Right Side View (二叉樹的右檢視)
題目描述: 給定一棵二叉樹,想象自己站在它的右側,按照從頂部到底部的順序,返回從右側所能看到的節點值。 示例: 輸入: [1,2,3,null,5,null,4] 輸出: [1, 3, 4] 解釋: 1 <--- / \ 2
leetcode question 199:Binary Tree Right Side View
問題: Given a binary tree, imagine yourself standing on the right side of it, return the values of the
#Leetcode# 199. Binary Tree Right Side View
https://leetcode.com/problems/binary-tree-right-side-view/ Given a binary tree, imagine yourself standing on the right side of it, retur
JavaScript刷LeetCode -- 199. Binary Tree Right Side View [Medium]
一、題目 &emmsp;Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from
[LeetCode 199] Binary Tree Right Side View (遞迴的層數)
題目內容 199 Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of
LeetCode 199 Binary Tree Right Side View(二叉樹層序遍歷)
Given a binary tree, imagine yourself standing on therightside of it, return the values of the node
【LeetCode】199. Binary Tree Right Side View
Problem:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from to
199. Binary Tree Right Side View
boolean des empty vid sin using tom als null 題目: Given a binary tree, imagine yourself standing on the right side of it, return the value
199. Binary Tree Right Side View -----層序遍歷
span ott ane sta esc style stand you question Given a binary tree, imagine yourself standing on the right side of it, return the values o
[Swift]LeetCode199. 二叉樹的右檢視 | 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. E
199 Binary Tree Right Side View
題目: Given a binary tree, imagine yourself standing on the right side of it, return the values of
199. Binary Tree Right Side View - Medium
lee plan ise edi mos example init solution cep Given a binary tree, imagine yourself standing on the right side of it, return the values