国产探花免费观看_亚洲丰满少妇自慰呻吟_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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固镇县| 冕宁县| 江陵县| 墨竹工卡县| 那坡县| 瑞丽市| 景泰县| 江孜县| 阜新市| 镇平县| 唐海县| 河西区| 澄城县| 罗定市| 辰溪县| 邵武市| 河北区| 响水县| 宣恩县| 柘荣县| 武汉市| 宜良县| 通榆县| 湘乡市| 临泽县| 贡嘎县| 昭平县| 邓州市| 吴江市| 偏关县| 宜兰县| 西乡县| 合肥市| 萝北县| 文化| 额济纳旗| 筠连县| 长顺县| 天门市| 安丘市| 宣城市|