leetcode-python-反转链表
第一轮解法:
1)双指针,先给定尾部为空,然后逐个出栈
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseList(self, head: ListNode) -> ListNode: tail = None temp = head while temp: temp = head.next head.next = tail tail = head head = temp # tail.PrintListNode() return tail

浙公网安备 33010602011771号