# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
if head==None:
return
odd=head
even_head=even=head.next
while odd.next and even.next:
odd.next=odd.next.next
even.next=even.next.next
odd=odd.next
even=even.next
odd.next=even_head
return head
LEETCODE 328. 奇偶链表
最新推荐文章于 2024-11-04 12:20:00 发布