我对在 Python 中递归反转链表的算法有疑问。
def reverse(lis, prev = None): if lis.next != None: reverse(lis.next, lis) lis.next = prev
输入: 3 1 4
3 1 4
输出: 3
3
知道为什么它不起作用吗?
python algorithm linked-list
algorithm ×1
linked-list ×1
python ×1