劍指offer——03從尾至頭打印列表(Python3)

思路:至關於數據結構中的鏈表就地逆置,可使用頭插法來實現。數據結構

代碼:spa

class Solution:
     # 返回從尾部到頭部的列表值序列,例如[1,2,3]
     def printListFromTailToHead( self , listNode):
         # write code here
         = []
         head  = listNode
         while head:
             l.insert( 0 , head.val)
             head  = head. next
         return l
相關文章
相關標籤/搜索