372.Definition of ListNode
单项列表只能把后一个node中的所有数据copy到当前node再delete后一node。
/**
* Definition of ListNode
* class ListNode {
* public:
* int val;
* ListNode *next;
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param node: the node in the list should be deletedt
* @return: nothing
*/
void deleteNode(ListNode * node) {
// write your code here
node->val = node->next->val;
ListNode *tmp = node->next;
node ->next = node->next->next;
delete tmp;
}
};
372.Definition of ListNode的更多相关文章
- Lintcode 372. O(1)时间复杂度删除链表节点
----------------------------------- AC代码: /** * Definition for ListNode. * public class ListNode { * ...
- 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 ...
- 372 在O(1)时间复杂度删除链表节点
原题网址:http://www.lintcode.com/zh-cn/problem/delete-node-in-the-middle-of-singly-linked-list/ 给定一个单链表中 ...
- leetcode & lintcode for bug-free
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
- (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)
--------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...
- Lintcode 166. 链表倒数第n个节点
----------------------------------- 最开始的想法是先计算出链表的长度length,然后再从头走 length-n 步即是需要的位置了. AC代码: /** * De ...
- Lintcode 102.带环链表
------------------------ 只要设置两个指针,称为快慢指针,当链表没有环的时候快指针会走到null,当链表有环的时候快指针早晚会追上慢指针的. AC代码: /** * Defin ...
- LintCode Reverse LinkedList (ArrayList 和 LinkedList 的区别)
1. ArrayList 和 LinkedList 的区别 http://pengcqu.iteye.com/blog/502676 2. How to reverse LinkedList http ...
随机推荐
- Nginx 安装配置
Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. ...
- C. Ayoub and Lost Array cf dp
C. Ayoub and Lost Array time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 关于HashMap的一些深入探索与理解
在java中.大家差点儿是离不开对集合的使用的,像Map系列,List系列.Set系列.可是非常多人没有了解过或者研究过这些集合类究竟能够用在什么地方,而且有什么注意的地方.因此本文分Map系列和Li ...
- 基于BeautifulSoup库的HTML内容的查找
一.BeautifulSoup库提供了一个检索的参数: <>.find_all(name,attrs,recursive,string,**kwargs),它返回一个列表类型,存储查找的结 ...
- SQL模糊查询排序问题
每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 需求描述 查询表中名字带指定关键字的数据 完全匹配放在第一位 前匹配放在第二位 ...
- 4-cookie 简介
1.eclipse中tomcate镜像位置:D:\javaTools\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\ ...
- pytorch .detach() .detach_() 和 .data用于切断反向传播
参考:https://pytorch-cn.readthedocs.io/zh/latest/package_references/torch-autograd/#detachsource 当我们再训 ...
- docker 4 docker的三要素
docker三要素 镜像,容器,仓库 镜像 docker镜像(image)就是一个只读的模板,镜像可以用来创建docker容器,一个镜像可以创建很多个容器 容器 docker利用容器(containe ...
- @ConfigurationProperties 配置详解
文章转自 https://blog.csdn.net/qq_26000415/article/details/78942494 前言新的一年到了,在这里先祝大家新年快乐.我们在上一篇spring bo ...
- ajax如何增加请求头
代码如下(主要关键就是headers,大家可以根据需要来增加请求头): $.ajax({ type: "POST", timeout: , // 超时时间 10 秒 headers ...