Maximum Depth of Binary Tree

/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
private: int height;
public:
    int maxDepth(TreeNode *root) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
     if(root==NULL)

      return 0 ;       

      height = 0;

        findDep(root,0);
        return height;
    }
    void findDep(TreeNode *node,int high)
    {
        if(node->left==NULL && node->right==NULL)
        {
            if(high+1>height)
            {
                height = high+1;
            }
        }
        if(node->left!=NULL)
        {
            findDep(node->left,high+1);
        }
        if(node->right!=NULL)
        {
            findDep(node->right,high+1);
        }
    }
};
原文地址:https://www.cnblogs.com/727713-chuan/p/3314661.html