104. Maximum Depth of Binary Tree
来源:互联网 发布:网络管理与维护论文 编辑:程序博客网 时间:2024/05/18 17:42
/*
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.
60%
*/
/***
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root) {
int i,j;
if(root==NULL)
return 0;
i = maxDepth(root->left);
j = maxDepth(root->right);
return i>j?i+1:j+1;
}
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.
60%
*/
/***
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root) {
int i,j;
if(root==NULL)
return 0;
i = maxDepth(root->left);
j = maxDepth(root->right);
return i>j?i+1:j+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
- 如何使用git新建多个SSH密钥进行项目托管
- servlet多文件上传文件(servlet3.0上传方式)
- IO、NIO、AIO 内部原理分析
- git初步使用
- LuoguP1890 gcd区间
- 104. Maximum Depth of Binary Tree
- 使用CollapsingToolbarLayout实现可展开与收缩的导航栏
- 错误Cannot change version of project facet Dynamic Web Module to 3.0: 在项目右键属性的Project facts中把Dynamci W
- Java-个位数统计 (15)
- IE下使用bootstrap-fileinput清空文件框并设置可用时文件框格式错误
- 在装有win10的电脑中安装Ubuntu16.04双系统遇到的问题及解决方案
- HTML5新特性及应用
- 重新更新博客了。。。
- Java入门基础之【StringBuffer和StringBuilder类】12