[LeetCode] Maximum Depth of Binary Tree

http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/

史上最简单的题了...

 1 class Solution {
 2 public:
 3     int maxDepth(TreeNode *root) {
 4         // IMPORTANT: Please reset any member data you declared, as
 5         // the same Solution instance will be reused for each test case.
 6         if (root == NULL) {
 7             return 0;
 8         } 
 9         return max(maxDepth(root->left) + 1, maxDepth(root->right) + 1);
10     }
11 };

 

posted @ 2013-11-05 01:06  NextLife  阅读(142)  评论(0)    收藏  举报