喜欢就点个收藏吧,嘿嘿
前言
一、为什么要从尾到头打印一个链表?
1.因为我们设计的数据结构是没有双向指针的,指针的指向永远都是后一个,所以需要设计一个算法出来
二、代码
class Solution(object):
def printListReversingly(self, head):
"""
:type head: ListNode
:rtype: List[int]
"""
if head == None:
return []
nums = []
while head != None:
nums.append(head.val)
head = head.next
ans = nums[::-1]
return ans