86. Partition List

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def partition(self, head, x):
        """
        :type head: ListNode
        :type x: int
        :rtype: ListNode
        """
        #dummy node to keep track of the head and tail of the smaller list and larger list 
        h1=t1=ListNode(0)
        h2=t2=ListNode(0)
        while head:
            if head.val

你可能感兴趣的:(86. Partition List)