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.

Show Tags
Show Similar Problems

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

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

  1. 【4_237】Delete Node in a Linked List

    Delete Node in a Linked List Total Accepted: 48121 Total Submissions: 109297 Difficulty: Easy Write ...

  2. Leetcode-237 Delete Node in a Linked List

    #237.    Delete Node in a Linked List Write a function to delete a node (except the tail) in a singl ...

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

  4. 【LeetCode】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements

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

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

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

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

  9. LeetCode_237. Delete Node in a Linked List

    237. Delete Node in a Linked List Easy Write a function to delete a node (except the tail) in a sing ...

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

随机推荐

  1. Java 线程池

    系统启动一个线程的成本是比较高的,因为它涉及到与操作系统的交互,使用线程池的好处是提高性能,当系统中包含大量并发的线程时,会导致系统性能剧烈下降,甚至导致JVM崩溃,而线程池的最大线程数参数可以控制系 ...

  2. postgresql 9.2之前的版本 需要CREATE LANGUAGE plpgsql

    CREATE LANGUAGE plpgsql CREATE or REPLACE function getDatirenshu(w_wjID int) RETURNS INTEGER as ' DE ...

  3. windows下最好的豆瓣fm软件——K.F.storm豆瓣电台,没有之一

    哈哈,发现windows下最好的豆瓣电台啦~~~基本全部功能都能满足哈,绝对没有之一的软件--K.F.storm豆瓣电台. 官方地址: http://www.kfstorm.com/blog/doub ...

  4. php示例代码之 使用PHP的MySQL标准函数

    <?php //连接参数 $host="localhost"; $user="root"; $pwd="111111"; $db=&q ...

  5. #VSTS定制#全新的模版定制能力

    在应用生命周期管理(ALM)领域中,存在各种不同的管理模型,如:传统的瀑布(waterfall)模型,CMMI模型以及最近一些年开始流行的敏捷模型,Scrum模型,kanban等等.每个不同的管理模型 ...

  6. 如何编译ReactNative示例程序Examples

    通过示例程序可以看到一些基本组件的使用,对于学习ReactNative是很有帮助的. 编译示例程序需要将整个项目导入到androidStudio中,androidStudio导入项目时选择react- ...

  7. docker-5 docker仓库

    docker部署环境:CentOS release 6.5 (Final) Docker配置文件:/etc/sysconfig/docker  重要参数解释: -H 表示Docker Daemon绑定 ...

  8. JavaScript获取元素CSS属性

    function getDefaultStyle(obj,attribute){ return obj.currentStyle?obj.currentStyle[attribute]:documen ...

  9. xsd.exe的使用

    xsd.exe的使用 XML文件生成XSD文件 xsd myFile.xml   /outputdir:myOutputDir XSD文件生存实体类 xsd <你的XSD路径>.xsd / ...

  10. 超链接a的target属性

    <a>标签的target意思很明确就是在哪里打开目标文档. 第一种情况: 默认情况:当我们没有设置超链接属性target的value值时默认是_self,即<a target=&qu ...