My simple java solution is


#1
public ListNode partition(ListNode A, int B) {
    ListNode temp=A;
   ListNode head1=null;
   ListNode tail1=null;
   ListNode head2=null;
   ListNode temp2=null;
    ListNode tail2=null;
    if(temp.next==null)
    {
        return temp;
    }
    while(temp!=null)
    {
        if(temp.val<B)
        {
            temp2=new ListNode(temp.val);
            if(head1==null)
            {
                head1=tail1=temp2;
                
            }
            else
            {
                tail1.next=temp2;
                tail1=temp2;
            }
        }
        else
        {
            temp2=new ListNode(temp.val);
            if(head2==null)
            {
                head2=tail2=temp2;
               
            }
            else
            {
                tail2.next=temp2;
                tail2=temp2;
            }
        }
       temp=temp.next;
    }
    if(head1==null)
    {
        A=head2;
        return A;
    }
    
    A=head1;
    tail1.next=head2;
    return A;
}