[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 ...
 
随机推荐
- Delphi应用程序的调试(五)其他调试工具
			
Delphi应用程序的调试(五)其他调试工具 Delphi7中提供了一些附加调试工具来帮助用户检查程序错误.从性能上讲,其中一些工具属于高级调试工具.尽管高级调试工具不像其他工具那样常用,但对于经验丰 ...
 - Twitter的SnowFlake分布式id生成算法
			
二进制相关知识回顾 1.所有的数据都是以二进制的形式存储在硬盘上.对于一个字节的8位到底是什么类型 计算机是如何分辨的呢? 其实计算机并不负责判断数据类型,数据类型是程序告诉计算机该如何解释内存块. ...
 - 求组合数 C++程序
			
一 递归求组合数 设函数为void comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...
 - sencha touch Carousel 自动切换
			
代码是在网上找的,忘记原出处了 /** * 跑马灯自动切换 */ Ext.define('ux.RotatingCarousel', { extend: 'Ext.carousel.Carousel' ...
 - [转] 基于TINY4412的Andorid开发-------简单的LED灯控制
			
阅读目录 一.编写驱动程序 二.编写代码测试驱动程序 三.编写HAL代码 四.编写Framework代码 五.编写JNI代码 六.编写App 参考资料: <Andriod系统源代码情景分析> ...
 - 获取Web.config的内容
			
<web.config> web.config文件是一个XML文件,它的根结点是<configuration>,在<configuration>节点下的常见子节点有 ...
 - vmware新建Ubuntu时,提示此主机不支持 Intel VT-x
			
有两种解决方式 一.BIOS中打开CPU虚拟选项,不同厂商主板配置不同: 以下以个人thinkpad T460P电脑为例: 1.关机,开机,在启动时,按F1今天 BIOS 设置页面: 2.选择 Sec ...
 - vue--双向数据绑定
			
<template> <div id="app"> <p>{{msg}}</p> <input v-model="m ...
 - 初学Listener
			
一. Listener 介绍 Servlet API提供了大量监听器来监听web应用的的内部事件,从而允许当web内部事件发生时回调事件监听器内的方法. 使用listener分为两步 定义LIsten ...
 - 专访知乎张伟:RFC技术评审机制如何助力知乎实现工程文化落地
			
2017年5月20-21日,MPD工作坊·上海站将于上海徐汇区光大会展中心举办,本届MPD工作坊请到了知乎工程高级总监张伟进行主题为<工程师文化落地6项指南>的3小时深度分享.在工作坊举办 ...