328. Odd Even Linked Lis

# 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:
            odd_tail=head
            even_tail=head.next
            while even_tail and even_tail.next:
                temp=odd_tail.next
                odd_tail.next=even_tail.next
                even_tail.next=odd_tail.next.next
                odd_tail.next.next=temp
                odd_tail=odd_tail.next
                even_tail=even_tail.next 
        return head 

你可能感兴趣的:(328. Odd Even Linked Lis)