Skip to content

Commit 4eb4806

Browse files
author
huangxiaofei
committed
modified: algorithms/cpp/maximumDepthOfBinaryTree/maximumDepthOfBinaryTree.cpp
使用 max 函数以及递归 精简实现
1 parent 2c9f3c2 commit 4eb4806

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

‎algorithms/cpp/maximumDepthOfBinaryTree/maximumDepthOfBinaryTree.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ class Solution {
4040
}
4141

4242
};
43+
44+
class Solution2 {
45+
public:
46+
int maxDepth(TreeNode *root) {
47+
if (root==NULL) return 0;
48+
return max(maxDepth(root->left), maxDepth(root->right)) + 1;
49+
}
50+
};

0 commit comments

Comments
 (0)