File tree 1 file changed +18
-18
lines changed
1 file changed +18
-18
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class PartitionList {
4
4
public ListNode partition (ListNode head , int x ) {
5
- ListNode list1 = new ListNode (0 );
6
- ListNode list2 = new ListNode (0 );
7
- ListNode temp1 = list1 ;
8
- ListNode temp2 = list2 ;
9
- while (head !=null ){
10
- if (head .val <x ){
11
- temp1 .next = head ;
12
- temp1 = temp1 .next ;
13
- }else {
14
- temp2 .next = head ;
15
- temp2 = temp2 .next ;
16
- }
17
- head = head .next ;
18
- }
19
- temp2 .next =null ;
20
- temp1 .next = list2 .next ;
21
- return list1 .next ;
22
- }
5
+ ListNode list1 = new ListNode (0 );
6
+ ListNode list2 = new ListNode (0 );
7
+ ListNode temp1 = list1 ;
8
+ ListNode temp2 = list2 ;
9
+ while (head !=null ){
10
+ if (head .val <x ){
11
+ temp1 .next = head ;
12
+ temp1 = temp1 .next ;
13
+ }else {
14
+ temp2 .next = head ;
15
+ temp2 = temp2 .next ;
16
+ }
17
+ head = head .next ;
18
+ }
19
+ temp2 .next =null ;
20
+ temp1 .next = list2 .next ;
21
+ return list1 .next ;
22
+ }
23
23
}
You can’t perform that action at this time.
0 commit comments