XIaohe-LeetCode 104 Maximum Depth of Binary Tree

This is the best solution.4ms

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
  int max(int x, int y)
  {
    if(x<=y)
      return y;
    else
      return x;
  }
  int maxDepth(struct TreeNode* root) {
    if(root==NULL)
    {
      return 0;
    }
    else
    {
      return max(maxDepth(root->left),maxDepth(root->right))+1;
    }
  }

posted @ 2015-11-22 10:27  CathyXiaohe  阅读(95)  评论(0编辑  收藏  举报