博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode&Python] Problem 237. Delete Node in a Linked List
阅读量:5174 次
发布时间:2019-06-13

本文共 1252 字,大约阅读时间需要 4 分钟。

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Given linked list -- head = [4,5,1,9], which looks like following:

4 -> 5 -> 1 -> 9

Example 1:

Input: head = [4,5,1,9], node = 5Output: [4,1,9]Explanation: You are given the second node with value 5, the linked list             should become 4 -> 1 -> 9 after calling your function.

Example 2:

Input: head = [4,5,1,9], node = 1Output: [4,5,9]Explanation: You are given the third node with value 1, the linked list             should become 4 -> 5 -> 9 after calling your function.

Note:

  • The linked list will have at least two elements.
  • All of the nodes' values will be unique.
  • The given node will not be the tail and it will always be a valid node of the linked list.
  • Do not return anything from your function.
 
# Definition for singly-linked list.# class ListNode(object):#     def __init__(self, x):#         self.val = x#         self.next = Noneclass Solution(object):    def deleteNode(self, node):        """        :type node: ListNode        :rtype: void Do not return anything, modify node in-place instead.        """        node.val=node.next.val        node.next=node.next.next

  

转载于:https://www.cnblogs.com/chiyeung/p/9950725.html

你可能感兴趣的文章
Android Volley 的基本使用/设置HTTP请求参数、apikey
查看>>
Hibernate框架
查看>>
Vim编辑器的使用总结
查看>>
ArcGIS REST 缓存清除(地图空白不显示的问题 )
查看>>
第0次作业
查看>>
"类" 库添加继承
查看>>
ucos在s3c2410上运行过程整体剖析之基础知识-与UCOS运行有关的ARM9芯片知识--续 ...
查看>>
存储器的寻址问题 分类: 计算机组成原理 2011-...
查看>>
DDRmenu(翻译)
查看>>
atitit.文件上传带进度条的实现原理and组件选型and最佳实践总结O7
查看>>
Atitit 架构的原则attilax总结
查看>>
ASP.Net之数据绑定
查看>>
Android自动化测试第三季第二讲Toast控件文字获取
查看>>
Google Analytics的能与不能
查看>>
Ubuntu 基本操作
查看>>
JAVA数组的定义及用法
查看>>
18寒假第七测
查看>>
帧中继
查看>>
105:MyBatis常见实用面试题整理
查看>>
Base on QC Automation Framework v1.0
查看>>