FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_02/id_124/LeetCode_783_124.java at master · feixiangcode/algorithm · GitHub
feixiangcode
/
algorithm
Public
forked from
algorithm001/algorithm
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_02
/
id_124
/
LeetCode_783_124.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (27 loc) · 827 Bytes
Breadcrumbs
algorithm
/
Week_02
/
id_124
/
LeetCode_783_124.java
Copy path
File metadata and controls
31 lines (27 loc) · 827 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
import
common
.
TreeNode
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
java
.
util
.
Stack
;
public
class
MinDiffInBST
{
public
int
minDiffInBST
(
TreeNode
root
) {
List
<
Integer
>
nlist
=
new
ArrayList
<>();
Stack
<
TreeNode
>
stack
=
new
Stack
<>();
TreeNode
node
=
root
;
while
(
node
!=
null
|| !
stack
.
isEmpty
()){
while
(
node
.
left
!=
null
){
stack
.
push
(
node
);
node
=
node
.
left
;
}
if
(!
stack
.
isEmpty
()){
TreeNode
t
=
stack
.
pop
();
nlist
.
add
(
t
.
val
);
node
=
t
.
right
;
}
}
int
min
=
Integer
.
MAX_VALUE
;
for
(
int
i
=
1
;
i
<
nlist
.
size
() ;
i
++){
min
=
Math
.
min
(
min
,
nlist
.
get
(
i
) -
nlist
.
get
(
i
-
1
));
}
return
min
;
}
}
Back
|
FazBrowse Home
|
New Git URL