public static ListNode partition(ListNode head, int x) {
        ListNode dummyHead1 = new ListNode(-1);
        ListNode dummyHead2 = new ListNode(-1);
        ListNode dummy1 = dummyHead1;
        ListNode dummy2 = dummyHead2;

        ListNode node = head;
        while(node != null){
            if(node.val < x){
                dummy1.next = node;
                dummy1 = dummy1.next;
            }else{
                dummy2.next = node;
                dummy2 = dummy2.next;
            }
            node = node.next;
        }
        dummy2.next = null;
        dummy1.next = dummyHead2.next;
        return dummyHead1.next;
    }