Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李楚霏
/
leetCode_Solution_Record
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
da7df576
authored
Aug 19, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2020/819
parent
525204b3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
2叉树最大深度.cpp
+22
-0
No files found.
2叉树最大深度.cpp
0 → 100644
View file @
da7df576
/**
/**
* 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
getDepth
(
TreeNode
*
node
){
if
(
node
==
nullptr
)
return
0
;
//判断指针为空的判断要放在这里,否则下面会报错
return
1
+
max
(
getDepth
(
node
->
left
),
getDepth
(
node
->
right
));
}
int
maxDepth
(
TreeNode
*
root
)
{
return
getDepth
(
root
);
}
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment