#372 Delete Node in the Middle of Singly Linked List
来源:互联网 发布:java项目实战视频 编辑:程序博客网 时间:2024/05/16 10:22
题目描述:
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
Example
题目思路:Given 1->2->3->4
, and node 3
. return 1->2->4
这题有点偷换概念:明明是要delete当前node,但是在啥都不知道的情况下,我们只能copy来下一个node,然后让下一个node当删除的替罪羊了。
Mycode(AC = 39ms):
/** * 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 // copy next node's value, and // delete next node node->val = node->next->val; node->next = node->next->next; }};
0 0
- #372 Delete Node in the Middle of Singly Linked List
- LinkedList---Delete Node in the Middle of Singly Linked List
- Delete Node in the Middle of Singly Linked List
- LintCode 372: Delete Node in the Middle of Singly Linked List
- LintCode Delete Node in the Middle of Singly Linked List 在O(1)时间复杂度删除链表节点
- 372.Delete Node in the Middle of Singly Linked List-在O(1)时间复杂度删除链表节点(容易题)
- 【11】Delete a node in the middle of a single linked list
- [CrackCode] 2.3 Delete a node in the middle of a single linked list
- Ch2-3: remove the middle node in a singly linked list
- Q.2.3 Implement an algorithm to delete a node in the middle of a single linked list, given only acce
- PIQ18: Delete middle node of a linked list
- fwnx - find the middle node in the linked list ~~~
- Ch2-2: return the nth to the last node data of a singly linked list
- leetcode: Delete Node in a Linked List
- LeetCode Delete Node in a Linked List
- Delete Node in a Linked List
- 【leetcode】Delete Node in a Linked List
- Delete Node in a Linked List
- HotSpot虚拟机对象
- Linux shell脚本中#! /bin/bash 与 #! /bin/sh 的区别
- Java 社区论坛 - Sym 1.5.0 发布
- JS 对输入框进行限制(常用的都有)
- MFC 读取配置文件(封装)
- #372 Delete Node in the Middle of Singly Linked List
- MYSQL初学——数据库与表的建立、修改、删除
- [绍棠][数学] 欧拉角、四元数
- node环境搭建开发
- Ubuntu 14.04+cuda8.0+opencv3.1+caffe
- jzoj 2051. 【8.18】极其简单的最短路问题
- Mysql的分页查询语句的性能分析
- Json串校验
- MFC全局函数AfxBeginThread 及其与CreateThread的区别