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 ...
随机推荐
- java+hibernate+mysql
实体类News package org.mythsky.hibernatedemo; import javax.persistence.*; @Entity @Table(name="new ...
- 删除qq互联
1.删除source/plugin 下的文件qqconnect文件夹 2.删除数据: DELETE FROM `dn_common_plugin` WHERE `identifier` = 'qqco ...
- 转:Intellij idea Version Control File Status Colors ( 版本控制文件状态颜色 )
https://blog.csdn.net/Bruce_Lee__/article/details/80261308 Added —— 添加 Added in not active changelis ...
- 装饰者模式——Java设计模式
装饰模式 1.概念 动态地为对象附加上额外的职责 其目的是包装一个对象,从而可以在运行时动态添加新的职责.每个装饰器都可以包装另一个装饰器,这样理论上来说可以对目标对象进行无限次的装饰. 2.装饰器类 ...
- Solidity数组
一.固定长度的数组(Arrays) 1.固定长度类型数组的声明 pragma solidity ^0.4.4; contract C { // 数组的长度为5,数组里面的存储的值的类型为uint类型 ...
- k8s使用nfs动态存储
1.Kubernetes集群管理员通过提供不同的存储类,可以满足用户不同的服务质量级别.备份策略和任意策略要求的存储需求.动态存储卷供应使用StorageClass进行实现,其允许存储卷按需被创建.如 ...
- 基于opencv将视频转化为字符串Java版
基于opencv将视频转化为字符串Java版 opencv java 先上一个效果图吧 首先,弄清一下原理 我们要将视频转化为字符画,那么就需要获取画面的每一帧,也就是每一张图片,然后将图片进行转化 ...
- 并发编程之 CAS 的原理
前言 在并发编程中,锁是消耗性能的操作,同一时间只能有一个线程进入同步块修改变量的值,比如下面的代码 synchronized void function(int b){ a = a + b: } 如 ...
- c# 导出text 文本文件
/// <summary> /// 机构代码信息 /// </summary> public static void ExportT_XQJBQK_SLGAJGDM(DataT ...
- Claim-Based Identity for Windows: Technologies and Scenarios
Claim-Based Identity for Windows: Technologies and Scenarios Active Diretory Federation Services 2.0 ...