题目描述
Python
blablabla
样例
blablabla
先取出链表的数据,然后两两交换
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def printListReversingly(self, head):
"""
:type head: ListNode
:rtype: List[int]
"""
res = []
while head is not None:
res.append(head.val)
head = head.next
if res == [] : return []
n = len(res)
l, r = 0, n - 1
while l < r:
res[l], res[r] = res[r], res[l]
l += 1
r -= 1
return res