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 ...
随机推荐
- 使用代数方程库 Algebra.js解二元一次方程
假设二元一次方程如下: x + y = 11 x - y = 5 解方程如下: <!DOCTYPE html> <html lang="zh-CN"> &l ...
- 读书笔记(01) - JSON - JavaScript高级程序设计
JSON与JavaScript对象 JSON是一种表示结构化数据的存储格式,语法格式上与JavasScript对象有些类似. TIPS: 与JavaScript对象的格式区别 不支持变量.函数或对象实 ...
- 研究CondItem
- 基于HA机制的MyCat架构——配置HAProxy
HAProxy简介HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProxy特别适用于那些负载特大的web站点,这些站 ...
- 每一行代码都有记录—如何用git一步步探索项目的历史
每一行代码都有一块被隐藏了的文档信息. 下面的代码片段不管是谁写的,其第4行因为某些原因要访问一个DOM结点的clientLeft属性,但却对结果不作任何处理.这十分的莫名其妙,你能告诉我他们为什么要 ...
- 【IT笔试面试题整理】反转链表
[试题描述]定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点 [参考代码] 方法一: public static Link reverseLinkList(Link head) ...
- 读jQuery源码释疑笔记3
1.在jQuery.fn=jQuery.prototype中定义了方法:init, map, each , toArray, get, pushStack, ready, slice,first ...
- Netty 高性能之道 FastThreadLocal 源码分析(快且安全)
前言 Netty 作为高性能框架,对 JDK 中的很多类都进行了封装了和优化,例如 Thread 类,Netty 使用了 FastThreadLocalRunnable 对所有 DefaultThre ...
- Win10 注册IIs4.0的解决方案
随着Win10的出现,越来越多的人装上了Win10,尤其是程序员,由于Win10是一个新的操作系统,但现有软件的兼容性等各方面都是未知,难免会存在很多坑,就拿IIS来说,我刚装完win10系统,然后装 ...
- java数组创建
java数组创建:int[] number = new int[10]; int[]:表明这是一个数组 new int[10]:给前面的数组类型的number变量分配10个int类型的空间大小