我遇到AttributeError:尝试反向链接列表时,“列表”对象没有属性“下一个”。
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def reverseList(self, head):
prev = None
while head:
curr = head
head = head.next
curr.next = prev
prev = curr
return prev
s = Solution()
s.reverseList([0,1,2,3,4,5])