FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/java/src/com.al/PartitionList.java at master · LionCoder4ever/algorithm · GitHub
LionCoder4ever
/
algorithm
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
13
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
java
/
src
/
com.al
/
PartitionList.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (49 loc) · 1.61 KB
Breadcrumbs
algorithm
/
java
/
src
/
com.al
/
PartitionList.java
Copy path
File metadata and controls
56 lines (49 loc) · 1.61 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
53
54
55
56
package
com
.
al
;
import
org
.
junit
.
jupiter
.
api
.
Test
;
public
class
PartitionList
{
@
Test
public
void
test
() {
Solution
s
=
new
Solution
();
ListNode
l
=
new
ListNode
(
1
);
l
.
next
=
new
ListNode
(
4
);
l
.
next
.
next
=
new
ListNode
(
3
);
l
.
next
.
next
.
next
=
new
ListNode
(
2
);
l
.
next
.
next
.
next
.
next
=
new
ListNode
(
5
);
l
.
next
.
next
.
next
.
next
.
next
=
new
ListNode
(
2
);
ListNode
ans
=
s
.
partition
(
l
,
3
);
System
.
out
.
println
(
"----------------"
);
while
(
ans
!=
null
) {
System
.
out
.
println
(
ans
.
val
);
ans
=
ans
.
next
;
}
}
class
ListNode
{
int
val
;
ListNode
next
;
ListNode
(
int
x
) {
val
=
x
; }
}
class
Solution
{
public
ListNode
partition
(
ListNode
head
,
int
x
) {
// add head node
ListNode
firstPartHead
=
new
ListNode
(-
1
),
secondPartHead
=
new
ListNode
(-
1
);
ListNode
firstLoop
=
firstPartHead
,
secondLoop
=
secondPartHead
;
ListNode
tmp
=
new
ListNode
(-
1
);
while
(
head
!=
null
) {
tmp
=
head
.
next
;
if
(
head
.
val
<
x
) {
firstLoop
.
next
=
head
;
firstLoop
=
firstLoop
.
next
;
firstLoop
.
next
=
null
;
}
else
{
secondLoop
.
next
=
head
;
secondLoop
=
secondLoop
.
next
;
secondLoop
.
next
=
null
;
}
head
=
tmp
;
}
secondLoop
.
next
=
null
;
firstLoop
.
next
=
secondPartHead
.
next
;
return
firstPartHead
.
next
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL