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 ...
随机推荐
- javascript:apply方法
1. apply和call的区别在哪里 2. 什么情况下用apply,什么情况下用call 3. apply的其他巧妙用法(一般在什么情况下可以使用apply ...
- js中 object.constructor
- android Installation error: INSTALL_FAILED_VERSION_DOWNGRADE
http://www.apkbus.com/android-114019-1-1.html 提高 AndroidManifest.xml中的manifest的android:versionCode ...
- WordPress主题开发:截取标题或内容
截取可以用wp_trim_words() 用法: <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ...
- Linux的命名空间详解--Linux进程的管理与调度(二)
转自:http://blog.csdn.net/gatieme/article/details/51383322 日期 内核版本 架构 作者 GitHub CSDN 2016-05-12 Linux- ...
- MySql错误处理(三)- 错误处理的例子
有几种错误处理的声明形式: § 如果任何错误(不是 NOT FOUND ) , 设置 l_error 为 1 后继续执行: DECLARE CONTINUE HANDLER FOR SQLEXCEPT ...
- Tomcat启动log打印到INFO: At least one JAR was scanned for TLDs yet contained no TLD各种解决方式
问题: 启动tomcat时,catalina.out日志打印到如下内容就停止不动了,也不报错 SEVERE: FarmWarDeployer can only work as host cluster ...
- Java获取当前时间30天之前的时间
//方法一 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String maxDateStr = " ...
- HTML5 浏览器返回按钮/手机返回按钮事件监听
1.HTML5 History对象 支持使用pushState()方法修改地址栏地址,而不刷新页面. popstate事件 当history实体被改变时,popstate事件将会发生.调用pushS ...
- PHP xhprof性能优化
xhprof window http://dev.freshsite.pl/php-extensions/xhprof.html http://php.net/manual/en/book.xhpro ...