104. Maximum Depth of Binary Tree
来源:互联网 发布:href javascript 编辑:程序博客网 时间:2024/06/06 07:46
递归解法:
/** * 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 maxDepth(TreeNode* root) { if(!root){ return 0; } int max = 0; int leftDepth = 0; int deep1 = maxDepth(root->left); int deep2 = maxDepth(root->right); return deep1 > deep2? deep1+1:deep2+1; }};
点击打开链接
0 0
- [LeetCode]104.Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 【LeetCode】104.Maximum Depth of Binary Tree
- [Leetcode] 104. Maximum Depth of Binary Tree
- LeetCode --- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- leetCode 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- leetcode:104. Maximum Depth of Binary Tree
- FPGA读取DRAM不成功的重要原因
- 算法竞赛入门经典(第2版)习题3-1 Uva1585
- 可变参数
- nginx架构介绍
- 微信小程序页面跳转传递值
- 104. Maximum Depth of Binary Tree
- 【APP推荐】手机制作微电影
- 在系统编程ISP及在应用编程IAP
- SpringAPI手动创建代理对象——ProxyFactory
- 十四、排列2
- 数据结构之顺序查找
- HTML5 canvas之旋转
- (计算几何)判断一个点是否在线段上
- django搭建个人博客08,添加访问权限