public static ListNode partition(ListNode head, int x) {
        // write your code here
        ListNode  c=head, d1=new ListNode(), d2=new ListNode(), p2=d2,p1=d1;
        d1.next=head;
        while (c!=null) {
            if (c.val<x) {
                p1.next=c.next;
                p2=p2.next=c;
            } else {
                p1=c;
            }
            c=c.next;
        }
        p2.next=d1.next;
        return d2.next;
    }