leetcode[104]:Maximum Depth of Binary Tree
2015-06-10 13:54
369 查看
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.
递归找子树即可。
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; }
递归找子树即可。
相关文章推荐
- MYSQL的binary解决mysql数据大小写敏感问题的方法
- 排序binary tree
- eclipse C/C++ 问题(launch failed,binary not found)
- launch failed.Binary not found in Linux/Ubuntu解决方案
- [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal
- Binary Tree Zigzag Level Order Traversal
- Construct Binary Tree from Preorder and Inorder Traversal
- Construct Binary Tree from Inorder and Postorder Traversal
- Flatten Binary Tree to Linked List
- Populating Next Right Pointers in Each Node II
- Gray Code
- Add Binary @ LeetCode java
- Mysql查询大小写不敏感简便解决办法
- Add Binary
- cf.256.div2.D
- Remove Node in Binary Search Tree
- linux 逆向
- Leetcode No.50: Pow(x, n)
- Binary Tree Postorder Traversal