题解 | #删除链表的节点#

删除链表的节点

https://www.nowcoder.com/practice/f9f78ca89ad643c99701a7142bd59f5d

class Solution:
    def deleteNode(self , head: ListNode, val: int) -> ListNode:
        # write code here
        if head.val == val:
            head = head.next
        else:
            pre = head
            now = head
            while now:
                if now.val == val:
                    pre.next = now.next
                    break
                pre = now
                now = now.next
        return head

全部评论

相关推荐

用微笑面对困难:只要你保证项目和获奖都是真的就行尤其是“对战,总负责人”啊这些套职,基本上队员,打杂的都这么写
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务