Skip to content

Commit 59d07f2

Browse files
authored
Update and rename maxDepth.cpp to maximum-depth-of-binary-tree.cpp
1 parent ba5cd71 commit 59d07f2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// Time: O(n)
2+
// Space: O(h)
3+
14
/**
2-
* Definition for binary tree
5+
* Definition for a binary tree node.
36
* struct TreeNode {
47
* int val;
58
* TreeNode *left;
@@ -9,9 +12,10 @@
912
*/
1013
class Solution {
1114
public:
12-
int maxDepth(TreeNode *root) {
13-
if(!root)
15+
int maxDepth(TreeNode* root) {
16+
if (!root) {
1417
return 0;
15-
return max(maxDepth(root->left), maxDepth(root->right))+1;
18+
}
19+
return max(maxDepth(root->left), maxDepth(root->right)) + 1;
1620
}
1721
};

0 commit comments

Comments
 (0)