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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

LeetCode:maximum-depth-of-binary-tree

2019-11-08 03:01:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int maxDepth(TreeNode *root) { if(root==NULL) return 0; if(root->left==NULL) return maxDepth(root->right)+1; else if(root->right==NULL) return maxDepth(root->left)+1; else return max(maxDepth(root->left),maxDepth(root->right))+1; }};
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 彰武县| 淮北市| 苍南县| 马山县| 道真| 辽源市| 绥滨县| 安图县| 陈巴尔虎旗| 广安市| 甘肃省| 金乡县| 泰来县| 纳雍县| 安义县| 华蓥市| 华安县| 五河县| 乳源| 甘孜| 靖西县| 唐海县| 莎车县| 炎陵县| 郴州市| 阜平县| 姚安县| 台山市| 上林县| 双江| 来宾市| 巧家县| 察哈| 资中县| 绿春县| 宜昌市| 资溪县| 仲巴县| 金湖县| 巴里| 德庆县|