FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_02/id_100/LeetCode_671_100.java at master · algorithm001/algorithm · GitHub
algorithm001
/
algorithm
Public
Notifications
You must be signed in to change notification settings
Fork
148
Star
118
Code
Issues
548
Pull requests
46
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_02
/
id_100
/
LeetCode_671_100.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (32 loc) · 1003 Bytes
Breadcrumbs
algorithm
/
Week_02
/
id_100
/
LeetCode_671_100.java
Copy path
File metadata and controls
34 lines (32 loc) · 1003 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
27
28
29
30
31
32
33
34
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class
Solution
{
public
int
findSecondMinimumValue
(
TreeNode
root
) {
return
traversal
(
root
,
root
.
val
);
}
private
static
int
traversal
(
TreeNode
root
,
int
rootVal
) {
if
(
root
==
null
) {
return
-
1
;
}
if
(
root
.
val
>
rootVal
) {
return
root
.
val
;
}
int
l
=
traversal
(
root
.
left
,
rootVal
);
// 遍历左节点值是否有大于根节点的值 3
System
.
out
.
println
(
"left ----> "
+
l
);
int
r
=
traversal
(
root
.
right
,
rootVal
);
// 遍历右节点值是否有大于根节点的值 7
System
.
out
.
println
(
"right --->"
+
r
);
// 如果左右节点都比跟节点大的话,取最小的
if
(
l
>=
0
&&
r
>=
0
) {
return
Math
.
min
(
l
,
r
);
}
// 否则取最大的
return
Math
.
max
(
l
,
r
);
}
}
Back
|
FazBrowse Home
|
New Git URL