LeetCode题解之Remove Nth Node From End of List
1、题目描述
2、问题分析
直接计算,操作。
3、代码
ListNode* removeNthFromEnd(ListNode* head, int n) {
if (head == NULL)
return head;
int len = ;
ListNode *p = head;
while (p != NULL) {
len++;
p = p->next;
} int step = len - n;
if (step == )
return head->next;
p = head;
while (--step) {
p = p->next;
} ListNode *tmp = p->next->next;
p->next = tmp; return head; }
LeetCode题解之Remove Nth Node From End of List的更多相关文章
- 《LeetBook》leetcode题解(19):Remove Nth Node From End of List[E]——双指针解决链表倒数问题
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 这个是书的地址: https://hk029.gitbooks.io/lee ...
- LeetCode题解(19)--Remove Nth Node From End of List
https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 原题: Given a linked list, remove the ...
- 【LeetCode】19. Remove Nth Node From End of List (2 solutions)
Remove Nth Node From End of List Given a linked list, remove the nth node from the end of list and r ...
- 【LeetCode】19. Remove Nth Node From End of List 删除链表的倒数第 N 个结点
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:链表, 删除节点,双指针,题解,leetcode, 力扣 ...
- 【一天一道LeetCode】#19. Remove Nth Node From End of List
一天一道LeetCode系列 (一)题目 Given a linked list, remove the nth node from the end of list and return its he ...
- 【LeetCode】019. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- LeetCode OJ 19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- 【LeetCode OJ】Remove Nth Node From End of List
题目:Given a linked list, remove the nth node from the end of list and return its head. For example: G ...
- LeetCode OJ:Remove Nth Node From End of List(倒序移除List中的元素)
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
随机推荐
- Kafka消费异常处理
org.apache.kafka.clients.consumer.CommitFailedException: Commit cannot be completed since the group ...
- wordpress添加面包屑
第一步:在functions.php中添加如下代码 // 面包屑导航 function get_breadcrumbs() { global $wp_query; if ( !is_home() ){ ...
- MongoDB安装配置教程
数据是每一前端人员必定接触的一样,所有的数据都是后端来编写,如果自己想练习项目,却没有数据,而是写一些假数据,去编写,或者通过json-server搭建一个数据,今天我们就通过MongoDB来搭建一个 ...
- mysql 解决 timestamp 的2038问题
当 timestamp 存储的时间大于 '2038-01-19 03:14:07' UTC,mysql就会报错,因为这是 mysql自身的问题,也就是说 timestamp是有上限的,超过了,自然会报 ...
- 《Netty权威指南》(一)走进 Java NIO
目录 1.1 I/O 基础入门 1.1.1 Linux 网络 I/O 模型 1.1.2 I/O 多路复用技术 2. Java 的 I/O 演进 1.1 I/O 基础入门 Java1.4 之前的早期 ...
- redis学习(二) redis数据结构介绍以及常用命令
redis数据结构介绍 我们已经知道redis是一个基于key-value数据存储的数据结构数据库,这里的key指的是string类型,而对应的value则可以是多样的数据结构.其中包括下面五种类型: ...
- gradle 转 maven
1. 预备 1.1. java 环境 验证 java -version 1.2. gradle 安装, 参考, 这里列举下windows下的安装 b.1 下载包:https://gradle.org/ ...
- LR监测windows资源一般监测哪几个项?
计数器 指标 1. 平均事务响应时间 Average Transation Response Time 优秀:<2s 良好:2-5s 及格:6-10s ...
- IIS 共享目录读写报错 Access to the path:“\\192.168.0.1\1.txt”is denied解决方案
这个是IIS权限的问题,主要修改了以下地方,如果两台电脑有相同的用户名和密码可以跳过第一步 1.找到共享目录的文件夹,属性=>共享,给电脑创建一个新用户,共享文件下添加新用户的读写权限,然后对应 ...
- 并发编程之 AQS 源码剖析
前言 JDK 1.5 的 java.util.concurrent.locks 包中都是锁,其中有一个抽象类 AbstractQueuedSynchronizer (抽象队列同步器),也就是 AQS, ...