国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

513. Find Bottom Left Tree Value

2019-11-08 02:00:28
字體:
來源:轉載
供稿:網友

Given a binary tree, find the leftmost value in the last row of the tree.

Example 1:

Input: 2 / / 1 3Output:1

Example 2:

Input: 1 / / 2 3 / / / 4 5 6 / 7Output:7

Note: You may assume the tree (i.e., the given root node) is not NULL.

/** * 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: int maxLevel = 0; int val; void dfs(TreeNode* root, int level){ if(root == NULL) return ; if(level > maxLevel){ maxLevel = level; val = root->val; } dfs(root->left, level + 1); dfs(root->right, level + 1); } int findBottomLeftValue(TreeNode* root) { val = root->val; dfs(root, 1); return val; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湖南省| 嘉善县| 乳源| 精河县| 绍兴市| 天全县| 南平市| 交城县| 峡江县| 临湘市| 巴塘县| 栖霞市| 临澧县| 商水县| 高密市| 霍州市| 西盟| 大庆市| 称多县| 嘉禾县| 涞源县| 南部县| 寿宁县| 九龙城区| 全州县| 东明县| 福贡县| 额敏县| 渭源县| 镇安县| 新平| 宜良县| 隆化县| 德令哈市| 南川市| 寻乌县| 射洪县| 商洛市| 商洛市| 永平县| 佛学|