Share python code, easy to understand.


  • 1
    class Solution(object):
    def oddEvenList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if not head or not head.next:return head
        p,q=head,head.next
        r=q
        while p.next and q.next:
            if p.next and p.next.next:
                p.next=p.next.next
                p=p.next
            if q.next and q.next.next:
                q.next=q.next.next
                q=q.next
        q.next=None
        p.next=r
        return head

Log in to reply
 

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