LeetCode86. 分隔链表
☆☆思路:要设置两个虚拟头节点
class Solution { public ListNode partition(ListNode head, int x) { if (head == null || head.next == null) return head; ListNode smallDummy = new ListNode(0); ListNode bigDummy = new ListNode(0); ListNode small = smallDummy; ListNode big = bigDummy; while (head != null) { if (head.val < x) { small.next = head; small = small.next; }else { big.next = head; big = big.next; } head = head.next; } big.next = null; small.next = bigDummy.next; return smallDummy.next; } }