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);
}
};

最新文章

  1. 用JS控制video暂停再播放
  2. 类似 Dribbble 下载按钮的 SVG 弹性动画进度条
  3. 点击页面其它地方隐藏div所想到的jQuery的delegate
  4. find只查当前目录 和 -exec和xargs区别
  5. FlashBuilder(FB/eclipse) 打开多个无效
  6. (medium)LeetCode 207.Course Schedule
  7. bzoj 1408 [Noi2002]Robot(欧拉函数)
  8. 插入ts以及判断列是否存在(支持多数据库)
  9. System.Management命名空间
  10. Java IO的RandomAccessFile的使用(转)
  11. 当ArcGIS10.2遇到Teradata
  12. linux 目录及文件的命名规则、ls操作
  13. golang kafka
  14. 启动Eclipse发生错误:An internal error occurred during: "Initializing Java Tooling".
  15. 浅谈spring中AOP以及spring中AOP的注解方式
  16. js对input框的可编辑属性设置
  17. easyui combobox下拉框文字超出宽度有横向滚轮
  18. javascript学习笔记(七):事件详解
  19. python 爬取全量百度POI
  20. Android Studio 设置代码提示和代码自动补全快捷键--Eclipse 风格 - 转

热门文章

  1. Scala实战高手****第16课:Scala implicits编程彻底实战及Spark源码鉴赏
  2. Scala零基础教学【41-60】
  3. Ubuntu 16.04通过APT源安装QUEM虚拟机调试Linux内核
  4. winfrom向窗体中拖放图片并显示
  5. SecureCRT的一些问题解决
  6. 【sql】关联查询+表自关联查询
  7. 怎么在VS2010中打开VS2013的项目
  8. BigDecimal的精度舍入模式详解
  9. cs-Panination
  10. http://blog.163.com/eugeneheen_chen@126/blog/static/120812157201291994916866/