[Python] I feel like something wrong with my solution

  • 0

    Even though it passed all the test cases, still I feel there might be something wrong that I can't tell, could anybody help to analyse

    class Solution(object):
        def partition(self, head, x):
            :type head: ListNode
            :type x: int
            :rtype: ListNode
            dummy = ListNode(None)
            dummy.next = head
            slow = dummy
            while slow.next and slow.next.val < x:
                slow = slow.next
            fast = slow
            while fast.next:
                if fast.next.val < x:
                    slow.next, slow.next.next, fast.next = fast.next, slow.next, fast.next.next
                    slow = slow.next
                    fast = fast.next
            return dummy.next

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.