-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time: 9 ms (24.79%), Space: 19.3 MB (6.11%) - LeetHub
- Loading branch information
1 parent
f403937
commit 70f20c3
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Definition for a binary tree node. | ||
* struct TreeNode { | ||
* int val; | ||
* TreeNode *left; | ||
* TreeNode *right; | ||
* TreeNode() : val(0), left(nullptr), right(nullptr) {} | ||
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | ||
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | ||
* }; | ||
*/ | ||
class Solution { | ||
public: | ||
int mx; | ||
int solve(TreeNode *root) | ||
{ | ||
if(root==NULL)return 0; | ||
return 1+max(solve(root->left),solve(root->right)); | ||
|
||
} | ||
int maxDepth(TreeNode* root) { | ||
return solve(root); | ||
} | ||
}; |