Skip to content

Instantly share code, notes, and snippets.

@hilda8519
Created June 25, 2014 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hilda8519/ddec0a1e20ac8074e79c to your computer and use it in GitHub Desktop.
Save hilda8519/ddec0a1e20ac8074e79c to your computer and use it in GitHub Desktop.
import java.util.List;
public class ListPartition {
public static void ListPartition(ListNode node, int x){
ListNode beforeStart=null;
ListNode afterStart=null;
while (node!=null){
ListNode next=node.next;
if(node.val<x){
node.next=beforeStart;
beforeStart=node;
}
else{
node.next=afterStart;
afterStart=node;
}
node=next;
}
if(beforeStart==null){
return;
}
ListNode head=beforeStart;
while(beforeStart.next!=null){
beforeStart=beforeStart.next;
}
beforeStart.next=afterStart;
return;
}
class ListNode {
int val;
ListNode next;
ListNode(int x, int i, int j, int k, int l, int m, int n, int o, int p, int q) {
val = x;
next = null;
}
}
public static void main(String[] args){
ListNode ListNode = new ListNode(1,2,3,4,5,7,8,9,10,11 );
System.out.print(ListPartition(ListNode, 10));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment