Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.

Have you met this question in a real interview?

 
 
Example

Given 1->2->3->4, and node 3. return 1->2->4

LeetCode上的原题,请参见我之前的博客Delete Node in a Linked List

class Solution {
public:
/**
* @param node: a node in the list should be deleted
* @return: nothing
*/
void deleteNode(ListNode *node) {
node->val = node->next->val;
ListNode *tmp = node->next;
node->next = tmp->next;
delete tmp;
}
};

[LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点的更多相关文章

  1. LintCode: Delete Node in the Middle of Singly Linked List

    开始没看懂题目的意思,以为是输入一个单链表,删掉链表中间的那个节点. 实际的意思是,传入的参数就是待删节点,所以只要把当前节点指向下一个节点就可以了. C++ /** * Definition of ...

  2. [LintCode] Linked List Cycle 单链表中的环

    Given a linked list, determine if it has a cycle in it. ExampleGiven -21->10->4->5, tail co ...

  3. LeetCode 876. Middle of the Linked List(获得链表中心结点)

    题意:获得链表中心结点.当有两个中心结点时,返回第二个. 分析:快慢指针. /** * Definition for singly-linked list. * struct ListNode { * ...

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

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

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

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

  7. 237. Delete Node in a Linked List

    在链接列表中删除节点. 编写一个函数来删除单链表中的一个节点(除了尾部),只提供对该节点的访问..假设链表是1 - > 2 - > 3 > 4,并给出了具有值为3的节点, 链表应该成 ...

  8. 372. Delete Node in a Linked List【LintCode java】

    Description Implement an algorithm to delete a node in the middle of a singly linked list, given onl ...

  9. [CareerCup] 2.3 Delete Node in a Linked List 删除链表的节点

    2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access ...

随机推荐

  1. PHP常量详解:define和const的区别

    常量是一个简单值的标识符(名字).如同其名称所暗示的,在脚本执行期间该值不能改变(除了所谓的魔术常量,它们其实不是常量).常量默认为大小写敏感.通常常量标识符总是大写的. 可以用 define() 函 ...

  2. 父类方法返回子类实例:PHP延迟静态绑定

    案例分析 先前的PHP项目中,看到类似于以下的一段代码: <?php class DBHandler { public function get() { } } class MySQLHandl ...

  3. PHP mysql与mysqli事务详解

    官方对PHP连接到MySQL数据库服务器的三种主要的API简介如下: http://php.net/manual/zh/mysqli.overview.php PHP mysql与mysqli事务详解 ...

  4. shell--4.echo和printf

    1. echo (1) echo ,显示普通字符串 echo "HelloWorld" 打印:HelloWorld (2) \ ,显示转义字符串 echo "\" ...

  5. CI在ngnix的配置

    CI的访问路径是酱紫的: http://localhost/index.php/cname/mname 其中cname为controller的名称,mname为method的名称 但是nginx会把i ...

  6. "转" CXF+JAXB处理复杂数据

    CXF简单数据类型以及类(JavaBean)都提供了较好的支持. 但是对于一些复杂类型(集合或者Map的嵌套)的处理时,就需要我们进行“”人工干预“.在网上找了一些文章,其中这篇写的最为详细,再次备注 ...

  7. [Linux]Linux系统调用列表

    本文列出了大部分常见的Linux系统调用,并附有简要中文说明. 以下是Linux系统调用的一个列表,包含了大部分常用系统调用和由系统调用派生出的的函数.这可能是你在互联网上所能看到的唯一一篇中文注释的 ...

  8. Android笔记:数据储存

    1.文件存储 文件存储是Android 中最基本的一种数据存储方式,它不对存储的内容进行任何的格式化处理,所有数据都是原封不动地保存到文件当中的,因而它比较适合用于存储一些简单的文本数据或二进制数据. ...

  9. winform 多个label绑定一个事件

    1当多个label帮到到一个事件后 private void jiandao_Click(object sender, EventArgs e) { //sender显示的是窗体上接受事件的label ...

  10. 《图形学》实验六:中点Bresenham算法画圆

    开发环境: VC++6.0,OpenGL 实验内容: 使用中点Bresenham算法画圆. 实验结果: 代码: #include <gl/glut.h> #define WIDTH 500 ...