Python | Leetcode Python题解之第203题移除链表元素

题目:

题解:

python 复制代码
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def removeElements(self, head: ListNode, val: int) -> ListNode:
        dummy_head = ListNode(next=head) #添加一个虚拟节点
        cur = dummy_head
        while(cur.next!=None):
            if(cur.next.val == val):
                cur.next = cur.next.next #删除cur.next节点
            else:
                cur = cur.next
        return dummy_head.next
相关推荐
楠楠子呀2 分钟前
从零构建高性能 WhatsApp 链接生成器与重定向服务:架构与路由解析
redis·python·容器·架构·flink·散列表·flume
OPEN-F9 分钟前
Python进阶教程:算法与数据结构入门
开发语言·python
薛定猫AI19 分钟前
【技术干货】Claude Code多模型代理与反馈闭环:Python实现可验证的AI编程工作流
开发语言·python·ai编程
每天一道题29 分钟前
从 async/await 到幂等恢复:把 Python 并发和 Agent Runtime 一次讲清楚
分布式·python
一只积极向上的小咸鱼36 分钟前
pytorch 与资源核算
人工智能·pytorch·python
reasonsummer40 分钟前
【办公类110-08】20260807园园通-“小班“户籍地址和居住地址补充完整+外省市所在“省市区”两个按钮手工填写(Python+EXCEL)
python·excel·园园通
whcyhhh41 分钟前
头歌实践教学平台:数据科学与大数据技术导论(五)
大数据·数据库·python
overmind43 分钟前
oeasy python 139 字典排序_快速生成_sorted
python