class ListNode:
def __init__(self, x):
if isinstance(x, int):
self.val = x
self.next = None
elif isinstance(x, list):
self.val = x[0]
self.next = None
head = self
for i in range(1,len(x)):
node = ListNode(x[i])
head.next = node
head = head.next
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
a, b = None, head
while b:
c = b.next
b.next = a
a = b
b = c
return a
n = int(sys.stdin.readline().strip())
point = []
for i in range(n):
point.append(list(map(int, sys.stdin.readline().strip().split())))
ll = ListNode(point)
k = Solution()
num = k.reverseList(ll)
while num:
print(num.val)
num = num.next
python反转链表
于 2022-08-26 11:41:06 首次发布
521

被折叠的 条评论
为什么被折叠?



