Python simple solution O(1) space O(n) time

  • 0
    class Solution(object):
        def oddEvenList(self, head):
            :type head: ListNode
            :rtype: ListNode
            if not head: return head
            odd = rootodd = head
            even = rooteven =
            while even and
                n1 =
                n2 =
       = n1
       = n2
                odd, even = n1, n2
   = rooteven
            return rootodd

Log in to reply

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