python AC 55ms


  • 0
    V
    class Solution(object):
        def oddEvenList(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            if not head or not head.next:
                return head
            
            lastOdd = cur = head
            evenHead = head.next
            i=1
            while cur and cur.next:
                nextPointer = cur.next
                cur.next =  cur.next.next
                cur = nextPointer
                i+=1
                if i%2 == 1:
                    lastOdd = cur
                
            print(lastOdd.val)
            lastOdd.next = evenHead
            return head
    

Log in to reply
 

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