Simple Python Solution


  • 0
    T
    class Solution(object):
        def oddEvenList(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            if head==None or head.next==None or head.next.next==None:
            	return head
            odd_node=head
            even_stater=head.next
            while odd_node.next!= None and odd_node.next.next!=None:
            	even_node=odd_node.next
            	odd_node.next=even_node.next
            	odd_node=odd_node.next
            	even_node.next=odd_node.next
            odd_node.next=even_stater
            return head
    

  • 0
    W

    very nice code, will be better if you use 'is None'


Log in to reply
 

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