[LeetCode] 237. Delete Node in a Linked List_Easy tag: Linked List
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 = 5
Output: [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 = 1
Output: [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.
因为没有办法去得到前面一个node的next, 所以我们可以将下一个node copy给当前的node值, 然后把node.next去掉即可. 机智.
Code
# 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.
"""
node.val = node.next.val
node.next = node.next.next
[LeetCode] 237. Delete Node in a Linked List_Easy tag: Linked List的更多相关文章
- [LeetCode] 237. Delete Node in a Linked List 解题思路
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- [LeetCode] 237. Delete Node in a Linked List 删除链表的节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- (easy)LeetCode 237.Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- leetcode 237 Delete Node in a Linked List python
题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...
- 17.leetcode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- [Leetcode]237. Delete Node in a Linked List -David_Lin
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- LeetCode 237. Delete Node in a Linked List 删除链表结点(只给定要删除的结点) C++/Java
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- LeetCode 237 Delete Node in a Linked List 解题报告
题目要求 Write a function to delete a node (except the tail) in a singly linked list, given only access ...
随机推荐
- grep和sed替换文件中的字符串【转】
sed -i s/"str1"/"str2"/g `grep "str1" -rl --include="*.[ch]" ...
- 【规范】alibaba编码规范阅读
一.编程规范 (一)命名规范 1.代码中的命名均不能以下划线或美元符号开始,也不能以下划线或美元符号结束 2.代码中的命名严禁使用评语与英文混合的方式,更不允许直接使用中文的方式 3.类名使用Uppe ...
- SPClaimsUtility.AuthenticateFormsUser的证书验证问题
Log Parser Studio查看IIS日志发现调用SPClaimsUtility.AuthenticateFormsUser的部分有time-taken在15秒左右的多个响应,查看call st ...
- HTML中块级元素与内联元素有什么区别 ?
块级元素:默认宽度是100%(继承自父元素),如果块对象没有采用“float:left”或“float:right;”的样式,相邻的两个块对象就会分排在不同的两行上.例如,div, p, h1, fo ...
- java的前缀自增自减和后缀自增自减
2.前缀自增自减法(++a,--a): 先进行自增或者自减运算,再进行表达式运算. 3.后缀自增自减法(a++,a--): 先进行表达式运算,再进行自增或者自减运算 实例: 实例 public cla ...
- iOS - 开源框架、项目和学习资料汇总(动画篇)
动画 1. Core Animation笔记,基本的使用方法 – Core Animation笔记,基本的使用方法:1.基本动画,2.多步动画,3.沿路径的动画,4.时间函数,5.动画组.2. awe ...
- 9.14.16 Django ORM进阶用法
2018-9-14 14:26:45 ORM 练习题 : http://www.cnblogs.com/liwenzhou/articles/8337352.html 2018-9-14 21:1 ...
- 170810、spring+springmvc+Interceptor+jwt+redis实现sso单点登录
在分布式环境中,如何支持PC.APP(ios.android)等多端的会话共享,这也是所有公司都需要的解决方案,用传统的session方式来解决,我想已经out了,我们是否可以找一个通用的方案,比如用 ...
- iptables、防火墙配置、NAT端口映射
一,配置一个filter表放火墙 (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables -L -n Chain INPUT (policy ACCEPT) targ ...
- jQuery的下面是动态表格动态表单中的HTML代码
动态表格动态表单中的Jquery代码 <script type="text/javascript" src="/include/jquery/jquery-1.1. ...