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

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.

class Solution {
public:
void deleteNode(ListNode* node) {
if (node == NULL) {}
else {
ListNode* tmp = node->next;
node->val = tmp->val;
node->next = tmp->next;
delete tmp;
}
}
};

Linked List-237. Delete Node in a Linked List的更多相关文章

  1. 237. Delete Node in a Linked List(C++)

    237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...

  2. LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List

    283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...

  3. 237. Delete Node in a Linked List【easy】

    237. Delete Node in a Linked List[easy] Write a function to delete a node (except the tail) in a sin ...

  4. [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 ...

  5. (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 ...

  6. 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 ...

  7. 【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 t ...

  8. 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 ...

  9. 237. Delete Node in a Linked List(leetcode)

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

  10. 【一天一道LeetCode】#237. Delete Node in a Linked List

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

随机推荐

  1. 3.说一下你了解的弹性FLEX布局.

    页面布局一直都是web应用样式设计的重点 我们传统的布局方式都是基于盒模型的 利用display.position.float来布局有一定局限性 比如说实现自适应垂直居中 随着响应式布局的流行,CSS ...

  2. Laravel Nginx 站点配置文件(Homestead)

    server {     listen 80;     listen 443 ssl http2;     server_name fmtmis.local;     root "/home ...

  3. sklearn中的分词函数countVectorizer()的改动--保留长度为1的字符串

    1简述问题 使用countVectorizer()将文本向量化时发现,文本中长度唯一的字符串会被自动过滤掉,这对于我在做的情感分析来讲,一些表较重要的表达情感倾向的词汇被过滤掉,比如文本'没用的东西, ...

  4. 如何通过cmd命令进入到某个硬盘的文件夹

    1.使用快捷键win+R打开运行窗口,并输入cmd回车 2.进入到某个磁盘:在命令提示符中输入d:(代表的的是进入D盘的根目录)并回车 3.接着在cmd中输入dir(dir是directory目录的简 ...

  5. 2018.10.04 NOIP模拟 排队(组合数学)

    传送门 T2原题啊. 直接组合数学求出合法方案数,再除去一个(n+m)!(n+m)!(n+m)!: ans=0(n<m)ans=0(n<m)ans=0(n<m) ans=n+1−mn ...

  6. 2018.09.09 UVa10529 - Dumb Bones(期望dp)

    传送门 期望dp好题. f[i]表示摆放i个的最小花费,于是f[i]可以从f[j]与f[i-j+1]转移过来了. 代码: #include<bits/stdc++.h> #define N ...

  7. hdu-1698(线段树,区间修改)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 注意:用位运算会更快,不然超时. #include<iostream> #inclu ...

  8. UVa 10881 Piotr's Ants (等价变换)

    题意:一个长度为L的木棍上有n个蚂蚁,每只蚂蚁要么向左,要么向右,速度为1,当两只蚂蚁相撞时, 它们同时掉头.给定每只蚂蚁初始位置和朝向,问T秒后,每只蚂蚁的状态. 析:刚看到这个题时,一点思路也没有 ...

  9. (转)Entity Framework Extended Library (EF扩展类库,支持批量更新、删除、合并多个查询等)

    转自:http://www.cnblogs.com/jinzhao/archive/2013/05/31/3108755.html 今天乍一看,园子里居然没有关于这个类库的文章,实在是意外毕竟已经有很 ...

  10. 理解maven项目的pom.xml文件中,<scope>标签的作用——作用域以及依赖传递

    问题介绍: 在maven项目中,最关键的就是pom.xml这个文件,这个文件是用来导入maven项目依赖的jar包以及一些插件等. 在这个文件中导入jar包使用的标签是<dependency&g ...