题解 | #从尾到头打印链表#

从尾到头打印链表

http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035

-- coding:utf-8 --

class ListNode:

def init(self, x):

self.val = x

self.next = None

class Solution: # 返回从尾部到头部的列表值序列,例如[1,2,3] def init(self): self.l = list()

def printListFromTailToHead(self, listNode):
    # write code here
    cur = listNode
    while cur:
        self.l.append(cur.val)
        if cur.next:
            cur = cur.next
        else:
            break
    return self.l[::-1]
全部评论

相关推荐

Dream_coding:你是不是只投大厂了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务