leetcode[104]:Maximum Depth of Binary Tree
来源:互联网 发布:阿里云 证书被ios信任 编辑:程序博客网 时间:2024/05/22 10:34
Maximum Depth of Binary Tree
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 a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */int maxDepth(struct TreeNode* root) { int i, j; i=j=1; if(!root) return 0; if(root->left) i += maxDepth(root->left); if(root->right) j += maxDepth(root->right); if( i > j ) return i; return j;}
递归找子树即可。
0 0
- Leetcode 104 Maximum Depth of Binary Tree
- LeetCode(104)Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- LeetCode: Maximum Depth of Binary Tree [104]
- 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
- 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
- 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
- Leetcode #104 Maximum Depth of Binary Tree
- leetcode 104: Maximum Depth of Binary Tree
- POJ - 2724 Purifying Machine 二分图 最大匹配
- Winsock编程流程(1)-TCP/IP
- git忽略对已入库文件的修改
- 整合spring、redis
- TCP/IP, WebSocket 和 MQTT
- leetcode[104]:Maximum Depth of Binary Tree
- Java NIO:NIO概述
- 下面宏的作用是什么 结构体
- SAT数学:必背公式之三角函数
- 封装,继承和多态
- 学习Android切割图片并保存到项目文件夹
- 彻底解决Spring MVC 中文乱码 问题
- UVALive 3135--Argus+自定义优先队列的优先规则
- JAVA基础--集合