problem
code
递归方法
/** * Definition for a binary tree node. * 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; return max(1+maxDepth(root->left), 1+maxDepth(root->right)); } };
参考
1.Maximum Depth of Binary Tree;
完