237. Delete Node in a Linked Lis

t

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.

Subscribe to see which companies asked this question

代码实现:

 /**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void deleteNode(ListNode* node) {
node->val = node->next->val;
ListNode *tmp = node->next;
node->next = tmp->next;
delete tmp;
}
};

237. Delete Node in a Linked List(C++)的更多相关文章

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

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

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

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

  5. [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 删除链表结点(只给定要删除的结点) C++/Java

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

  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. 【一天一道LeetCode】#237. Delete Node in a Linked List

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

  9. Leet Code OJ 237. Delete Node in a Linked List [Difficulty: Easy]

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

随机推荐

  1. 有7g和2g的砝码各一个,怎样称可以3次把140g东西分为50g和90g???????

    第一次:等分 50和90为   70 70 2.   7g 和2g  ,取出一个70中的9g   ,  61   70 3.利用 9g和2g砝码,取出61中的11克,前面的9 和 11 都放进70

  2. Asp.net MVC Razor Generator

    Razor Generator开源工具使用简介: “Razor Generator” 前生“Razor Single File Generator for MVC” 这可以将MVC视图文件[.csht ...

  3. Hdu 4312-Meeting point-2 切比雪夫距离,曼哈顿距离,前缀和

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4312 Meeting point-2 Time Limit: 2000/1000 MS (Java/Ot ...

  4. Java多线程内存模型

    Java虚拟机规范中试图定义一种Java内存模型(Java Memory Model,JMM)来屏蔽掉各种硬件和操作系统的内存访问差异,以实现让Java程序在各种平台下都能达到一致的并发效果.在此之前 ...

  5. Axure RP 8.0 中继器初体验

    为了解决增删等复杂交互的问题,中继器是个不错的选择. 拖拽出一个默认的中继器 中继器的数据集感觉就像是数据库一样,在右边检视窗口中可以看到中继器的默认数据集,可以理解成一张二维表.默认有1列,现成的3 ...

  6. 什么时候使用Shell

    因为Shell似乎是各UNIX系统之间通用的功能,并且经过了POSIX的标准化.因此,Shell脚本只要“用心写”一次,即可应用到很多系统上.因此,之所以要使用Shell脚本是基于: 简单性:Shel ...

  7. Redis未授权访问缺陷让服务器沦为肉鸡

    朋友的一个项目说接到阿里云的告警,提示服务器已沦为肉鸡,网络带宽被大量占用,网站访问很慢,通过SSH远程管理服务器还频繁断开链接.朋友不知如何下手,便邀请我帮忙处理. 阿里云的安全告警邮件内容: 在没 ...

  8. 360浏览器拦截弹窗,window.open方式打不开新页面

    window.open虽然在很多时候被广大中小站长用于弹窗广告的展示,所以广受争议,但是在业务需求中还是有很多场景需要用到此功能.然而,大多数浏览器对此都有一定的安全策略进行阻止,为此本文将针对以下浏 ...

  9. Anniversary Party

    Time limit: 0.5 second Memory limit: 8 MB Background The president of the Ural State University is g ...

  10. Linux的文件属性

    在Linux中,文件的拥有者可以将文件的属性设置成三种属性,可读(r).可写(w)和可执行(x).文件又分为三个不同的用户级别,文件的拥有者(u),文件的所属组(g),其他用户(o). 第一个字符显示 ...