删除链表的节点

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
class Solution:
    def deleteNode(self, head: ListNode, val: int) -> ListNode:
        dummy = ListNode(-1)
        dummy.next = head
        pre = dummy
        while pre.next:
            if pre.next.val == val:
                pre.next = pre.next.next
                break
            
            pre = pre.next
        
        return dummy.next
posted @   KbMan  阅读(29)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示