【发布时间】:2020-07-26 23:15:06
【问题描述】:
我在尝试反转链表时遇到链表循环错误-
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
first = head
second = head.next
third = head.next.next
while third != None and third.next != None:
third = second.next
second.next = first
first = second
second = third
print(first)
print (second)
return second
输出:[5]
错误是-
错误 - 在 ListNode 中找到循环 ListNode{val: 5, next: 无}
【问题讨论】:
-
知道如何调试这个问题吗?
标签: python-3.x algorithm