LeetCode:maximum-depth-of-binary-tree
来源:互联网 发布:java 微信 编辑:程序博客网 时间:2024/06/10 23:44
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; }};
0 0
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 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
- UVA-10128
- UVA-12563
- UVA-580
- 用Apache POI读取Excel并下载
- express 路由
- LeetCode:maximum-depth-of-binary-tree
- 30:Remove Duplicates from Sorted List
- lua + openresty web API 框架
- express.static 作用及用法
- linux下的静态库和动态库
- 树莓派新安装
- Linux下安装配置JavaJDK
- android 解析XML最常用的三种方式;DOM解析,SAX解析,PULL解析
- 字符串的反转