LintCode: Delete Node in the Middle of Singly Linked List
开始没看懂题目的意思,以为是输入一个单链表,删掉链表中间的那个节点。
实际的意思是,传入的参数就是待删节点,所以只要把当前节点指向下一个节点就可以了。
C++
/**
* Definition of ListNode
* class ListNode {
* public:
* int val;
* ListNode *next;
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param node: a node in the list should be deleted
* @return: nothing
*/
void deleteNode(ListNode *node) {
// write your code here
node->val = node->next->val;
node->next = node->next->next;
}
};
LintCode: Delete Node in the Middle of Singly Linked List的更多相关文章
- [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...
- 372. Delete Node in a Linked List【LintCode java】
Description Implement an algorithm to delete a node in the middle of a singly linked list, given onl ...
- [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 ...
- [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 ...
- 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 ...
- 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_237】Delete Node in a Linked List
Delete Node in a Linked List Total Accepted: 48121 Total Submissions: 109297 Difficulty: Easy Write ...
- 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 ...
- (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 ...
随机推荐
- 前端使用AngularJS的$resource,后端ASP.NET Web API,实现增删改查
AngularJS中的$resource服务相比$http服务更适合与RESTful服务进行交互.本篇后端使用ASP.NET Web API, 前端使用$resource,实现增删改查. 本系列包括: ...
- OLE文件拖放
使用IDropTarget接口同时支持文本和文件拖放 关于Windows的外壳扩展编程,拖放是比较简单的一种,在网上可以找到不少介绍这个技巧的文章.大部分是介绍使用MFC的COleDropTarget ...
- SQL Where in list 问题
不过,这种做法有两个缺陷1.Oracle In列表的数目有限制(1000)2.不能复用执行计划,每次几乎都是硬解析.3.In拼接可能存在SQL注入的风险
- iPhone开发中从一个视图跳到另一个视图有三种方法:
iPhone开发中从一个视图跳到另一个视图有三种方法: 1.self.view addSubView:view .self.window addSubView,需要注意的是,这个方法只是把页面加在 ...
- Android开发中,比较有特色的特性(与iOS相比)
1.界面代码和界面控件元素时时联动.同步 2.当我们创建一个Activity时,系统自动帮我们维护strings.xml 文件和AndroidManifest.xml文件. 3.有来无回,删除.修改时 ...
- cocos2d-x CC_SYNTHESIZE_READONLY
//定义一个只读属性Label,在类定义中可以使用this->getLabel来访问 CC_SYNTHESIZE_READONLY(cocos2d::CCLabelTTF*,_label ...
- 基于CentOS的MySQL学习补充三--使用Shell批量创建数据库表
本文出处:http://blog.csdn.net/u012377333/article/details/47006087 接上篇介绍<基于CentOS的Mysql学习补充二--使用Shell创 ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. 解决
ERROR - No operations allowed after connection closed. 2011-12-07 11:36:09 - ERROR - query failed or ...
- Javascript与Objective-C 字符串与数组的方法类比
table {border-collapse:collapse;} table td {border:1px solid #ccc;} String vs NSString JavaScript st ...
- sql语句 update 字段=字段+字符串
update aa set name=concat('x',name) SELECT OWNER,phone ,COUNT(fc_hc) as c from tb_p GROUP BY fc_hc H ...