FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/datastructure/recursion/Solution.java at master · wangguofei/JavaArithmetic · GitHub
wangguofei
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
datastructure
/
recursion
/
Solution.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (39 loc) · 1.34 KB
Breadcrumbs
JavaArithmetic
/
src
/
datastructure
/
recursion
/
Solution.java
Copy path
File metadata and controls
52 lines (39 loc) · 1.34 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package
datastructure
.
recursion
;
public
class
Solution
{
public
ListNode
removeElements
(
ListNode
head
,
int
val
,
int
depth
) {
String
depthString
=
generateDepthString
(
depth
);
System
.
out
.
print
(
depthString
);
System
.
out
.
println
(
"Call: remove "
+
val
+
" in "
+
head
);
if
(
head
==
null
){
System
.
out
.
print
(
depthString
);
System
.
out
.
println
(
"Return: "
+
head
);
return
head
;
}
ListNode
res
=
removeElements
(
head
.
next
,
val
,
depth
+
1
);
System
.
out
.
print
(
depthString
);
System
.
out
.
println
(
"After remove "
+
val
+
": "
+
res
);
ListNode
ret
;
if
(
head
.
val
==
val
)
ret
=
res
;
else
{
head
.
next
=
res
;
ret
=
head
;
}
System
.
out
.
print
(
depthString
);
System
.
out
.
println
(
"Return: "
+
ret
);
return
ret
;
}
private
String
generateDepthString
(
int
depth
){
StringBuilder
res
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
depth
;
i
++)
res
.
append
(
"--"
);
return
res
.
toString
();
}
public
static
void
main
(
String
[]
args
) {
int
[]
nums
= {
1
,
2
,
6
,
3
,
4
,
5
,
6
};
ListNode
head
=
new
ListNode
(
nums
);
System
.
out
.
println
(
head
);
ListNode
res
= (
new
Solution
()).
removeElements
(
head
,
6
,
0
);
System
.
out
.
println
(
res
);
}
}
Back
|
FazBrowse Home
|
New Git URL