Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f1979d

Browse files
committedJul 15, 2017
solution for: Partition List
1 parent 21e8a7b commit 1f1979d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎src/leetcode/PartitionList.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package leetcode;
2+
3+
public class PartitionList {
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+
}
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.