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.

更改当前节点的值来实现

 /**
* 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) {
if(node == NULL) return;
node->val = node->next->val;
node->next = node->next->next;
}
};

没什么好说的,下面是java版本的:

 /**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}
}

LeetCode OJ:Delete Node in a Linked List(链表节点删除)的更多相关文章

  1. Leetcode 237 Delete Node in a Linked List 链表

    如题 删除是要注意让现在的链表等于下一个链表的值 class Solution { public: void deleteNode(ListNode* node) { ListNode *nextno ...

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

  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: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. Java [Leetcode 273]Delete Node in a Linked List

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

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

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

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

随机推荐

  1. 笔画宽度变化(C++和matlab算法)

    最近一直在看工作方面的书籍,把论文的事情搁置了,之前承诺的贴代码的事一直拖.现在把代码整理发上来,只有核心部分的,都不是我写的,我是网上整理下载的,matlab代码的效果比较差. 全部文件网盘下载地址 ...

  2. 分布式计算开源框架Hadoop入门实践(二)

    其实参看Hadoop官方文档已经能够很容易配置分布式框架运行环境了,不过这里既然写了就再多写一点,同时有一些细节需要注意的也说明一下,其实也就是这些细节会让人摸索半天.Hadoop可以单机跑,也可以配 ...

  3. Java转C#,非常不错(转)

    http://www.cnblogs.com/cnwebman/archive/2012/07/21/2602436.html 最近正在研究将一个纯java工程如何转换成C#工程,代码量还比较大,于是 ...

  4. mysql分组查询报错

    执行sql group by查询时报错 SELECT id from userz GROUP BY username Expression #1 of SELECT list is not in GR ...

  5. sorted 、 filter 、 map

    sorted   排序函数 内置函数中提供了一个通用的排序方案 ,返回一个新的列表,不会改变原数据 语法: sorted(iterable, key, reverse) key: 排序方案, sort ...

  6. http://www.uupoop.com/ps/

    网页版PS,在线PS 基本的PS功能都有,最重要的一点是快,网页版的嘛,哼哼!

  7. 【Tech】SQL Server2008使用笔记

    1.64位win7系统报错“未在本地计算机上注册 Microsoft.ACE.OLEDB.12.0 ”. 解决方法:从这个网址下载和安装一个驱动http://www.microsoft.com/zh- ...

  8. CentOS 5下freeswitch中集成使用ekho实现TTS功能三

    四:在freeswitch中调用ekho 注:在测试过程中该语音包好像没用 FreeSWITCH 中文语音包测试版fssounds.zip 在/usr/local/freeswitch/sounds/ ...

  9. cocos2dx打飞机项目笔记四:Enemy类和EnemyLayer类

    Enemy类没什么内容,就create和init方法,根据参数来创建不同的敌机,头文件代码如下: //飞机的类型 enum planeType {smallPlane, midPlane, bigPl ...

  10. javax.mail.MessagingException: Could not connect to SMTP host: smtp.xdf.cn

    1.问题描述:关于使用Java Mail进行邮件发送,抛出Could not connect to SMTP host: xx@xxx.com, port: 25的异常可能: 当我们使用Java Ma ...