首页 > 其他 > 详细

链表的反转

时间:2020-05-17 17:52:50      阅读:47      评论:0      收藏:0      [点我收藏+]
class ListNode:
     def __init__(self, x):
         self.val = x
         self.next = None

class Solution:
    # 返回从尾部到头部的列表值序列,例如[1,2,3]
    def printListFromTailToHead(self, listNode):
        # write code here
        node=listNode
        res=[]
        while node:
            res.append(node.val)
            node=node.next
        return res[::-1]

思路:将链表的节点添加进列表,再对列表进行反转输出

链表的反转

原文:https://www.cnblogs.com/zxixiu/p/12906044.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!