```# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param head ListNode类
# @return ListNode类
#
class Solution:
def oddEvenList(self , head: ListNode) -> ListNode:
# write code here
"""
#转化成两个数组,分别储存奇数位,和偶数位
N1=[]
N2=[]
pre=head
count=1
while pre is not None:
if count %2==0:
N2.append(pre.val)
if count %2==1:
N1.append(pre.val)
pre=pre.next
count+=1
temp=N=ListNode(-1)
for _ in range(len(N1)):
N.next=ListNode(N1[_])
N=N.next
for _ in range(len(N2)):
N.next=ListNode(N2[_])
N=N.next
return temp.next
"""
#链表拆接
if not head:
return head
pre=head
N=head.next
cur=N
while cur is not None and cur.next is not None :
pre.next=cur.next
pre=pre.next
cur.next=pre.next
cur=cur.next
pre.next=N
return head
##### 1.转化成两个数组,分别储存奇数位,和偶数位,这样子做思路上简单,但是空间复杂度较大
2.链表拆接,将链表按照偶数位奇数位拆成两个小链表,在拼接在一起。