python 剑指offer系列:反转链表

xiaoxiao2021-02-28  82

题目:输入一个链表,反转链表后,输出链表的所有元素。

代码:

# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # 返回ListNode def ReverseList(self, head): # write code here tmp = None while head: cur = head.next head.next = tmp tmp = head head = cur return tmp
转载请注明原文地址: https://www.6miu.com/read-34125.html

最新回复(0)