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,
Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
Try to do this in one pass.
Subscribe to see which companies asked this question
解答:
额这道题没想出什么好方法……感觉这样要两次遍历好烦啊……当然链表嘛就要注意头节点……有空再看看吧TAT
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
struct ListNode *tmp = head;
;
while(NULL != tmp){
count++;
tmp = tmp->next;
}
if(count == n){
return head->next;
}
tmp = head;
){
count--;
tmp = tmp->next;
}
tmp->next = tmp->next->next;
return head;
}
LeetCode OJ 19. 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 (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
一天一道LeetCode系列 (一)题目 Given a linked list, remove the nth node from the end of list and return its he ...
- 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 删除链表的倒数第 N 个结点
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:链表, 删除节点,双指针,题解,leetcode, 力扣 ...
- 【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 ...
- [Leetcode][Python]19: Remove Nth Node From End of List
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 38: Count and Sayhttps://oj.leetcode.co ...
- LeetCode:19. Remove Nth Node From End of List(Medium)
1. 原题链接 https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/ 2. 题目要求 给出一个链表,请 ...
随机推荐
- Java关键字final、static使用总结(转)
原文链接:Java关键字final, static一些要点 1. final final类不能被继承,没有子类,final类中的方法默认是final的 final方法不能被子类的方法复盖,但可以被 ...
- 插件开发-滑条(slide)开发
自己一直很喜欢开发组件,只是OPP学的不是很精,自己在项目中用别人的框架进行项目开发,难免受制于人,也许这就是个人实际项目需求和框架提供的多少有点不符,引导我自己尝试开发一些自己常用的组件,话不多说, ...
- 深度学习 + OpenCV,Python实现实时视频目标检测
使用 OpenCV 和 Python 对实时视频流进行深度学习目标检测是非常简单的,我们只需要组合一些合适的代码,接入实时视频,随后加入原有的目标检测功能. 在本文中我们将学习如何扩展原有的目标检测项 ...
- 关于jdango框架静态文件配置的问题
一: 我们首先要知道什么是静态文件: 静态文件就是我们的HTML,css,图片等文件. 二: 我们要知道我们的Django框架是一个web服务器,那么web服务器,我们是通过一个url地址来访问它的, ...
- mocha、should、supertest释义
解释参考地址: https://itbilu.com/nodejs/npm/VyrFOe51-.html Mocha模块 Mocha是一个简单.可扩展的用于Node.js和JavaScript的单元测 ...
- JVM总结-垃圾回收(下)
大部分的 Java 对象只存活一小段时间,而存活下来的小部分 Java 对象则会存活很长一段时间. 之所以要提到这个假设,是因为它造就了 Java 虚拟机的分代回收思想.简单来说,就是将堆空间划分为两 ...
- c# 线程 WPF 进度百分比(菜鸟)
#region 线程执行 /// <summary> /// 线程运行,将改变的textblock值实时显示在前台 /// </summary> /// <param n ...
- 初识vuejs
转行前端,时间也不短了,也见识到了前端行业的蓬勃发展,以及一些新鲜技术的层出不穷. 由于自身计算机基础的薄弱,更加上一直没有遇上一个公司力推新技术,所以一直以来基本上都是靠着jquery和则zepto ...
- tensorflowwindows安装
1.在python官网下载3.5 64位版本的python,并进行安装 https://www.python.org/ 2.进行安装,配置环境变量 3.命令行执行pip3 install numpy ...
- raw格式和qcow2格式
Raw: "raw" 镜像格式是最最简单的,并且是被 KVM 和 Xen 原生支持的格式,你 可以想象裸格式镜像和块设备文件是二进制位相当的,就好像从块设备拷 贝过来的,比方说,使 ...