当前位置:网站首页>leetcode 链表类
leetcode 链表类
2022-07-26 19:58:00 【Yuki_1999】
206题:反转链表
方法一:双指针法
class Solution(object):
def reverseList(self, head):
pre=None
cur=head
while(cur!=None):
temp=cur.next
cur.next=pre
pre=cur
cur=temp
return pre #返回头结点
203题:移除链表元素
删除链表元素的方法
1)直接使用原来的链表来进行删除操作。
删除头结点:头结点向后移动一位,需要单独写
2)另设置一个虚拟头结点,指针cur从虚拟头结点开始遍历链表。
#虚拟头结点法
class Solution(object):
def removeElements(self, head, val):
dummy_head=ListNode(next=head)#设置虚拟头结点
cur=dummy_head
while(cur.next!=None):
if(cur.next.val==val):
cur.next=cur.next.next
else:
cur=cur.next
return dummy_head.next
边栏推荐
猜你喜欢

CentOS7关于Oracle RAC 11GR2部署磁盘分区问题

APP自动化测试框架搭建(八)--ATX Server2多设备集群环境搭建

【【实验分享】CCIE—BGP路由黑洞实验】
![Installation and configuration of [basic services] [database] Clickhouse](/img/fe/5c24e4c3dc17a6a96985e4fe97024e.png)
Installation and configuration of [basic services] [database] Clickhouse

Small scenes bring great improvement! Baidu PaddlePaddle easydl helps AI upgrade of manufacturing assembly line

BUU刷题记3

YGG cooperates with my pet hooligan, AMGI's flagship NFT project, to enter the rabbit hole

Gartner released the latest market guide for Chinese AI start-ups, and Hongji cyclone was once again rated as a representative enterprise

The sandbox cooperates with artist Alec monopoly

Read the four service types of kubernetes!
随机推荐
MPLS multi protocol label switching technology
A super simple neural network code with 5 coordinates for one layer node training
How to implement an asynchronous task queue system that can handle massive data (supreme Collection Edition)
YGG cooperates with my pet hooligan, AMGI's flagship NFT project, to enter the rabbit hole
Arpspoof installation and use
解决IBGP的水平分割和BGP选路原则
Depthwiseseparableconvolution: depthwise convolution and pointwise convolution
一层节点训练5个坐标的超简单神经网络代码
Ape tutoring's technological hard power: let AI start from reading children's homework
[基础服务] [数据库] ClickHouse的安装和配置
Pandonia spirit voxedit creation competition
Shell综合应用案例,归档文件
The 50 Smartest Companies in the world announced that Chinese manufacturers account for nearly half, and Huawei ranks first
opencv dnn部署onnx模型
BGP的基本配置和聚合
QT signal and slot connection (loose coupling)
Chat software project development 2
[Delphi] different platform descriptions of borderstyles of FMX form
"Enterprise management" sincere crm+ - integrated management of enterprise business processes
【【实验分享】CCIE—BGP路由黑洞实验】