Python solution


  • 0
    H
    # Definition for singly-linked list.
    # class ListNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution(object):
        def oddEvenList(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            if head==None or head.next==None:
                return head
            start1=head
            start2=head.next
            curr1=start1
            curr2=start2
            while curr2!=None and curr2.next!=None:
                curr1.next=curr1.next.next
                curr2.next=curr2.next.next
                curr1=curr1.next
                curr2=curr2.next
            curr1.next=start2
            return head

Log in to reply
 

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