leetcode 328. Odd Even Linked List

来源:互联网 发布:linux mount 绑定目录 编辑:程序博客网 时间:2024/06/07 01:38
# Definition for singly-linked list.# class ListNode(object):#     def __init__(self, x):#         self.val = x#         self.next = Noneclass Solution(object):    def oddEvenList(self, head):        """        :type head: ListNode        :rtype: ListNode        """        if head is None:            return head        odd_list = head        even_list = head.next        even_head = head.next        while even_list is not None:            odd_list.next = even_list.next            if odd_list.next is None:                break            odd_list = odd_list.next            even_list.next = odd_list.next            even_list = even_list.next        odd_list.next = even_head        return head
原创粉丝点击