Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
0086 Partition List
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# = None
class Solution:
def partition(self, head: ListNode, x: int) -> ListNode:
d1, d2 = ListNode(0), ListNode(0)
ite = [d1, d2]
while head:
nxt =
i = 0 if head.val < x else 1
ite[i].next = head
ite[i] = ite[i].next
ite[i].next = None;
head = nxt
if not return
if not return
ite[0].next =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.