leetcode之104. Maximum Depth of Binary Tree(C++解法)
来源:互联网 发布:淘宝网名龙堂 编辑:程序博客网 时间:2024/06/05 10:09
*****************************我是分割线************************
/**
* 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) {
int num;
if(root==NULL)
return 0;
else if(root->left==0 && root->right==0)
return 1;
else if(root->left==0)
return 1+maxDepth(root->right);
else if(root->right==0)
return 1+maxDepth(root->left);
else
{
int a=1+maxDepth(root->left);
int b=1+maxDepth(root->right);
return max(a,b);
}
}
};
这个还没有研究特别清楚啦,对树的操作还需要练习,(^__^) 嘻嘻……
- leetcode之104. Maximum Depth of Binary Tree(C++解法)
- LeetCode 104. Maximum Depth of Binary Tree 题解(C++)
- [C]LeetCode:Maximum Depth of Binary Tree
- LeetCode 之 Maximum Depth of Binary Tree
- LeetCode之Maximum Depth of Binary Tree
- LeetCode之Maximum Depth of Binary Tree
- leetcode 之 Maximum Depth of Binary Tree
- leetCode 之 Maximum Depth of Binary Tree
- LeetCode之Maximum Depth of Binary Tree
- leetcode之Maximum Depth of Binary Tree
- leetcode之 Maximum Depth of Binary Tree
- LeetCode之Maximum Depth of Binary Tree
- LeetCode之Maximum Depth of Binary Tree
- LeetCode 之 Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree C语言
- Leetcode-104. Maximum Depth of Binary Tree c语言
- LeetCode 104. Maximum Depth of Binary Tree (C++)
- [LeetCode] [C] 104. Maximum Depth of Binary Tree
- HDU 1048 The Hardest Problem Ever(字符串处理)
- 读大话设计模式Gof后的总结
- hdu5876 Sparse Graph(最短路)
- CSV JDBC 数据库Parameter Junit
- freemarker中的list
- leetcode之104. Maximum Depth of Binary Tree(C++解法)
- [初级教程]arm-linux裸机开发之-bootstrap.bin的实现
- Longest Palindromic Substring
- 写了个高仿内涵段子,iosapp,源码。
- Ubuntu 安装myeclipse 2014GA 添加swap swap交换空间
- leetcode之27. Remove Element(C++解法)
- 【给将来学神的算法详解--高精】(7)大大小小&其他符号
- 连续子数组的最大和 java实现
- android获取版本名称app