Skip to content

Commit a83f158

Browse files
committed
solution for: Partition List
1 parent 1f1979d commit a83f158

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/leetcode/PartitionList.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
public class PartitionList {
44
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+
}
2323
}

0 commit comments

Comments
 (0)