zoukankan      html  css  js  c++  java
  • 边工作边刷题:70天一遍leetcode: day 61-2

    Delete Node in a Linked List

    要点:简单题,把下一个值移到当前值,然后把下一个删除(就是node.next连接到node.next.next)
    错误点:

    • 注意不是和最后一个交换,之所以会错是因为要检查node是不是最后一个,只有不是队尾才能这么做
    • 不是循环左移,O(1)就行
    • node是队头没影响,因为是删除下一个
    # Definition for singly-linked list.
    # class ListNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution(object):
        def deleteNode(self, node):
            """
            :type node: ListNode
            :rtype: void Do not return anything, modify node in-place instead.
            """
            #cur = node
            if node.next:
                #pre = cur
                node.val=node.next.val
                node.next=node.next.next
            
            #pre.next = None
    
    
  • 相关阅读:
    MobileNet V1 V2
    异常检测 与 One Class SVM
    异常检测
    图像分割
    1x1卷积核的作用
    迁移学习
    python
    图像分割
    图像分割
    Nagios
  • 原文地址:https://www.cnblogs.com/absolute/p/5690335.html
Copyright © 2011-2022 走看看