Clean python code with Dummy Node

  • 0
    class Solution(object):
        def partition(self, head, x):
            dummyLHead = dummyLTail = ListNode(0)
            dummyGHead = dummyGTail = ListNode(0)
            while head:
                if head.val < x:
          , dummyLTail = head, head
          , dummyGTail = head, head
                head =
  , =, None

  • 0

    Hi, shiyanhui,
    I am a beginner of python. Could you tell me what is 'while head:' means here ? Does that mean when the head is not None, do the while loop ?

  • 0

    If I may, you are right.
    While head, would be true while head is Not None

Log in to reply

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