237. Delete Node in a Linked List【easy】

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) {
node->val = node->next->val; ListNode * temp = node->next;
node->next = temp->next;
free(temp);
}
};

237. Delete Node in a Linked List【easy】的更多相关文章

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

  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(C++)

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

  4. 160. Intersection of Two Linked Lists【easy】

    160. Intersection of Two Linked Lists[easy] Write a program to find the node at which the intersecti ...

  5. 206. Reverse Linked List【easy】

    206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...

  6. 234. Palindrome Linked List【easy】

    234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follo ...

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

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

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

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

随机推荐

  1. 【进制转换】CODEVS 1740 进制计算器

    #include<cstdio> #include<iostream> #include<string> using namespace std; string s ...

  2. 1.3(Mybatis学习笔记)动态SQL

    一.<if> 使用<if>可以根据具体情况来拼接SQL语句,使其更加灵活更加适应我们的需求. <if>的标签体中是需要拼接的语句,满足条件才会将其进行拼接. < ...

  3. Scala实战高手****第1课:大数据时代的“黄金”语言Scala

    共计28课,每节课程在1个小时左右. 每天至少2个课程.预计在11.30号完成. ——————————————————

  4. HDU 3389 Game(博弈)

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. tcpreplay 发包速率控制算法研究

    一.  序 1.1  tcpreplay历史 Tcpreplay 的作者是Aaron Turner,该项目开始于2000年,早期的功能是对tcpdump等抓包工具生成的网络包(即pcap文件)的回放, ...

  6. Python 操作mongodb 简单实例

    1.建立数据库用户 要读写 mongo数据库,默认没有用户名和密码也可以对数据库进行读写操作,但是从安全的角度,最好给要操作的数据库建立用户名和密码. 打开mongo数据库服务,打开mongo.exe ...

  7. python 未发现数据源名称并且未指定默认驱动程序

    最近在用python连接sqlserver读取数据库,读取数据时候在本机电脑正常,但是把程序部署到服务器运行时一直报错“未发现数据源名称并且未指定默认驱动程序”,后来发现是因为数据源的问题,解决如下: ...

  8. [转载]Java 反射机制(包括组成、结构、示例说明等内容)

    FROM:http://www.cnblogs.com/skywang12345/p/3345205.html 第1部分 Java 反射机制介绍 Java 反射机制.通俗来讲呢,就是在运行状态中,我们 ...

  9. 读取Properties配置文件, 四种方式都可以得到webroot/WEB-INF/classes这个路径

    下面四种方式都可以得到webroot/WEB-INF/classes这个路径,有什么区别,哪种方式最好? String path = this.getClass().getResource(" ...

  10. Windows利用命令行快速清除以及建立密码

    我们Win10一般是没有管理员权限的!这就要求我们获取管理员权限了,一般有两种方法获取,我就介绍下面一种最简单的 老操作:WIn+R打开本窗口,输入:taskmgr 建立密码(administrato ...