The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
我想不用多說了吧
code也很簡單...
class Solution { public: int maxDepth(TreeNode *root) { if(root == NULL) { return 0; } return 1 + max( maxDepth(root->left), maxDepth(root->right) ); } };搞定
沒有留言 :
張貼留言