基于python实现从尾到头打印链表
作者:小小文艺范 时间:2023-07-02 21:24:34
这篇文章主要介绍了基于python实现从尾到头打印链表,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
题目描述
输入一个链表,按链表从尾到头的顺序返回一个ArrayList。
思路
遍历链表,把结构保存在list里面,然后把list逆序输出
代码
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# 返回从尾部到头部的列表值序列,例如[1,2,3]
def printListFromTailToHead(self, listNode):
if not listNode:
return []
my_list = []
current = listNode
while current:
my_list.append(current.val)
current = current.next
my_list.reverse()
return my_list
来源:https://www.cnblogs.com/wangzhihang/p/11778219.html
标签:python,打印,链表
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python数据类型--字典dictionary
2023-06-19 12:49:53
![](https://img.aspxhome.com/file/2023/6/94106_0s.png)
python如何判断文件存在方式
2023-01-23 12:58:37
为什么从Python 3.6开始字典有序并效率更高
2021-03-26 15:29:36
![](https://img.aspxhome.com/file/2023/1/128261_0s.jpg)
Django 如何实现文件上传下载
2021-07-16 02:54:15
![](https://img.aspxhome.com/file/2023/0/86270_0s.png)
Bootstrap table学习笔记(2) 前后端分页模糊查询
2024-04-29 13:12:22
![](https://img.aspxhome.com/file/2023/6/132836_0s.jpg)
Python numpy中矩阵的基本用法汇总
2021-10-23 06:37:26
![](https://img.aspxhome.com/file/2023/6/114526_0s.png)
Java连接MySQL数据库增删改查的通用方法(推荐)
2024-01-22 12:00:36
解决使用export_graphviz可视化树报错的问题
2022-06-10 18:35:59
![](https://img.aspxhome.com/file/2023/2/84902_0s.jpg)
Webpack 实现 Node.js 代码热替换
2024-05-13 10:04:14
Vue组件之自定义事件的功能图解
2024-05-05 09:07:34
![](https://img.aspxhome.com/file/2023/8/130848_0s.png)
设计师如何更有效拿到结果?
2008-09-22 20:30:00
![](https://img.aspxhome.com/file/UploadPic/20089/22/2008922203620332s.jpg)
mysql 8.0.15 安装配置图文教程
2024-01-26 02:22:41
![](https://img.aspxhome.com/file/2023/7/70387_0s.jpg)
详解如何通过Mysql的二进制日志恢复数据库数据
2024-01-19 11:33:43
![](https://img.aspxhome.com/file/2023/8/79998_0s.png)
怎样使你的 JavaScript 代码简单易读(推荐)
2024-04-16 09:53:22
Python实现高效求解素数代码实例
2023-04-29 16:06:32
CSS Sprites对CSS布局的意义、优点和缺点介绍
2008-07-14 07:22:00
Python机器学习之基础概述
2021-07-18 19:07:59
![](https://img.aspxhome.com/file/2023/8/89408_0s.png)
Python创建简单的神经网络实例讲解
2021-12-02 05:38:41
![](https://img.aspxhome.com/file/2023/2/72762_0s.png)
python使用tensorflow保存、加载和使用模型的方法
2021-01-25 13:19:26
解决Unable to access 'https://gitee.com/自己的项目/': Could not resolve host: gitee.com问题
2023-11-06 06:47:59
![](https://img.aspxhome.com/file/2023/1/117501_0s.png)