当前位置:网站首页>Leetcode linked list class
Leetcode linked list class
2022-07-26 20:54:00 【Yuki_ one thousand nine hundred and ninety-nine】
206 topic : Reverse a linked list
Method 1 : Double finger needling
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 # Return to header node
203 topic : Remove linked list elements
How to delete a linked list element
1) Directly use the original linked list to delete the operation .
Delete header node : Head node moves backward by one bit , It needs to be written separately
2) Set another virtual head node , The pointer cur Start traversing the linked list from the virtual head node .
# Virtual head node method
class Solution(object):
def removeElements(self, head, val):
dummy_head=ListNode(next=head)# Set the virtual header node
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
边栏推荐
猜你喜欢

AI technology, simplifying the complex world | teatalk online application practical series, issue 2

每日练习------有一组学员的成绩,将它们按降序排列,要增加一个学员的成绩,将它插入成绩序列,并保持降序

Establishment of APP automation testing framework (VIII) -- establishment of ATX server2 multi device cluster environment

SSM integration example

Interceptors

Shell综合应用案例,归档文件

QT基础第一天 (1)QT,GUI(图形用户接口)开发

MPLS multi protocol label switching technology

NVIDIA canvas first experience~

81.(cesium之家)cesium修改灰色背景(默认蓝色)
随机推荐
QT driving school subject examination system -- from implementation to release
[Delphi] different platform descriptions of borderstyles of FMX form
Message queue -- the problem introduced: repeated consumption & sequential consumption & distributed transactions
Using union to sort MySQL
执行上下文与词法环境
BGP的路由黑洞和防环
The lawyer team of the US Department of justice asked the judge to refuse to accept Huawei's lawsuit
Bean注入和生命周期
【问题篇】将集合[‘‘,‘‘]处理成(‘‘,‘‘)
LeetCode_ Backtracking_ Medium_ 216. Combined sum III
没有网络怎么配置传奇SF登陆器自动读取列表
opencv dnn部署onnx模型
Gartner released the latest market guide for Chinese AI start-ups, and Hongji cyclone was once again rated as a representative enterprise
人脸识别、指纹识别都弱爆了?五角大楼研发远距离心跳识别
How to create a static object variable of its own class?
BGP--边界网关协议
Houdini finds the midpoint and connects the points to form a line
[experiment sharing] CCIE BGP routing black hole experiment]
BTC和ETH不确定性增强 因加息逼近?美国经济将面临更多痛苦
Gartner发布最新《中国AI初创企业市场指南》,弘玑Cyclone再次被评为代表性企业