讨论/《链表》 - 奇偶链表/
《链表》 - 奇偶链表

Python3

class Solution:
    def oddEvenList(self, head: ListNode) -> ListNode:
        """
        思路:需要有个指针对偶数节点头部进行记录
        方法:双指针
        """
        if not head:
            return head
        odd = head
        even = evenhead = head.next
        while even and even.next:
            odd.next = even.next
            odd = odd.next
            even.next = odd.next
            even = even.next
        odd.next = evenhead
        return head
展开全部 15 讨论