国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 乐业县| 霸州市| 冷水江市| 临沧市| 砚山县| 黑龙江省| 宁国市| 丰原市| 通许县| 武鸣县| 沽源县| 清流县| 洛扎县| 肥乡县| 滁州市| 绥德县| 丹东市| 横山县| 乐陵市| 辉南县| 肃南| 田阳县| 买车| 临沂市| 分宜县| 宜春市| 封开县| 垣曲县| 喀喇沁旗| 韶山市| 漳平市| 东阳市| 武平县| 崇文区| 蒙山县| 中宁县| 南陵县| 新宁县| 井冈山市| 德惠市| 东明县|