🟢 剑指 Offer 18. 删除链表的节点
LeetCode 提示
题目难度 简单
原题链接 🔗 leetcode
#
题解 1.py# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def deleteNode(self, head: ListNode, val: int) -> ListNode: fakeHead = ListNode(None) fakeHead.next = head l, r = fakeHead, head while r and r.val != val: l, r = r, r.next if r.val == val: l.next = r.next return fakeHead.next