# 86. Partition List

[Link](https://leetcode.com/problems/partition-list/)

**Solution**

這題我是切成左右兩半，一邊放\<x，另一邊放> x。

之後combine這兩半

```
   public ListNode partition(ListNode head, int x) {
        ListNode dummy = new ListNode(0);
        ListNode node = head;
        ListNode rightDummy = new ListNode(0);
        ListNode r = rightDummy;
        ListNode l = dummy;

        while(node != null){
            while(node != null && node.val >= x){
                rightDummy.next = node;
                rightDummy = rightDummy.next;
                node = node.next;   
            }
            if(node == null) break;
            else if(node.val < x){
                dummy.next = node;
                dummy = dummy.next;
                node = node.next;
            }
        }
        dummy.next = r.next;
        rightDummy.next = null;
        return l.next;
        
    }
```
