odd_even_linked_list
odd_even_linked_list.py 源码
# 奇偶链表
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def oddEvenList(self, head: ListNode) -> ListNode:
if not head:
return head
evenHead = head.next
odd, even = head, head.next
while even and even.next:
odd.next, odd = even.next, even.next
even.next, even = odd.next, odd.next
odd.next = evenHead
return head
你可能感兴趣的文章
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦