Python单链表逆置
来源:互联网 发布:pubmed数据库 编辑:程序博客网 时间:2024/05/20 20:47
1、循环反转单链表
# -*- coding:utf-8 -*-# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def ReverseList(self, pHead): if not pHead or not pHead.next: return pHead last = None while pHead: tmp = pHead.next pHead.next = last last = pHead pHead = tmp return last2、递归反转单链表
# -*- coding:utf-8 -*-# class ListNode:# def __init__(self, x):# self.val = x# self.next = Nonedef ReverseList(self, pHead): if head is None: return; if head.next is None: newhead=head; else : newhead=recurse(head.next,newhead);
head.next.next=head;
head.next=None; return newhead;
阅读全文
0 0
- Python单链表逆置
- python 单链表逆置
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- 剑指offer中连续子数组的最大和+最大的子序列和的问题
- JavaScript框架对比
- 微积分的历史演变与现状
- 什么是CS和BS结构,两种结构的区别
- 将你的 CentOS 变成 OSPF 路由器
- Python单链表逆置
- 进行Linux性能监控的命令介绍
- bzoj1013 [JSOI2008]球形空间产生器sphere(gauss)
- LeetCode:Valid Parentheses
- 线程
- codeforces 869C The Intriguing Obsession 组合数学,逆元
- RecyclerView使用Switchcompat not displaying the Switch
- mysql 修改数据表结构
- poj 3461 Oulipo KMP