237. Delete Node in a Linked List【easy】
2024-08-27 23:09:42
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);
}
};
最新文章
- 用JS控制video暂停再播放
- 类似 Dribbble 下载按钮的 SVG 弹性动画进度条
- 点击页面其它地方隐藏div所想到的jQuery的delegate
- find只查当前目录 和 -exec和xargs区别
- FlashBuilder(FB/eclipse) 打开多个无效
- (medium)LeetCode 207.Course Schedule
- bzoj 1408 [Noi2002]Robot(欧拉函数)
- 插入ts以及判断列是否存在(支持多数据库)
- System.Management命名空间
- Java IO的RandomAccessFile的使用(转)
- 当ArcGIS10.2遇到Teradata
- linux 目录及文件的命名规则、ls操作
- golang kafka
- 启动Eclipse发生错误:An internal error occurred during: ";Initializing Java Tooling";.
- 浅谈spring中AOP以及spring中AOP的注解方式
- js对input框的可编辑属性设置
- easyui combobox下拉框文字超出宽度有横向滚轮
- javascript学习笔记(七):事件详解
- python 爬取全量百度POI
- Android Studio 设置代码提示和代码自动补全快捷键--Eclipse 风格 - 转
热门文章
- Scala实战高手****第16课:Scala implicits编程彻底实战及Spark源码鉴赏
- Scala零基础教学【41-60】
- Ubuntu 16.04通过APT源安装QUEM虚拟机调试Linux内核
- winfrom向窗体中拖放图片并显示
- SecureCRT的一些问题解决
- 【sql】关联查询+表自关联查询
- 怎么在VS2010中打开VS2013的项目
- BigDecimal的精度舍入模式详解
- cs-Panination
- http://blog.163.com/eugeneheen_chen@126/blog/static/120812157201291994916866/