1. 从尾到头打印链表
输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)
方法:
def reverse_print(head):
res = []
node = head
while node is not None:
res.insert(0, node.val)
node = node.next
return res
1. 从尾到头打印链表
输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)
方法:
def reverse_print(head):
res = []
node = head
while node is not None:
res.insert(0, node.val)
node = node.next
return res