FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/LeetCode/LeetCode104.java at master · freestylewill/JavaArithmetic · GitHub
freestylewill
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode104.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (20 loc) · 649 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode104.java
Copy path
File metadata and controls
26 lines (20 loc) · 649 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package
LeetCode
;
public
class
LeetCode104
{
// 104. Maximum Depth of Binary Tree
// https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
// 时间复杂度: O(n), n是树中的节点个数
// 空间复杂度: O(h), h是树的高度
// Definition for a binary tree node.
public
class
TreeNode
{
int
val
;
TreeNode
left
;
TreeNode
right
;
TreeNode
(
int
x
) {
val
=
x
; }
}
public
int
maxDepth
(
TreeNode
root
) {
if
(
root
==
null
)
return
0
;
// 递归!!!!
return
1
+
Math
.
max
(
maxDepth
(
root
.
left
),
maxDepth
(
root
.
right
));
}
}
Back
|
FazBrowse Home
|
New Git URL