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. 题目要求 给出一个链表,请 ...
随机推荐
- Android通过包名启动其他应用,若该应用已启动,则直接将应用切到前台
CommUtil.startActivityForPackage(mContext, "com.autonavi.minimap");//打开高德 CommUtil.java /* ...
- uigrid配置详解(1)
$scope.gridOptions.rowTemplate = '<div style="background-color: aquamarine" ng-click=&q ...
- package.json-nodeJs
package.json文件描述了一个NPM包的所有相关信息,包括作者.简介.包依赖.构建等信息.格式必须是严格的JSON格式. 通常我们在创建一个NPM程序时,可以使用npm init命令,通过交互 ...
- Keras 实现一个简单GAN
Keras 实现一个简单GAN 代码中需提供: Loss Function 参见Keras 或者 Tensorflow 文档 model_param_matrix 反向调整的模型参数/参数矩阵 ...
- c#语言集合分析
集合的赋值: double fenshu = 0; al.Add(fenshu=double.Parse (Console .ReadLine ())); //如果是存数字,将来要比较大小,需要再添加 ...
- linux中的IP地址的修改
一,图形界面,setup 二,修改文件 1,修改主机名字 vi /etc/sysconfig/network NETWORKING=yes #HOSTNAME=localhost.localdomai ...
- 数据持久化—真机上的Plist写入
其实写入不到真机里面主要是你写入时,当前那文件夹里你要写入的plist根本不存在 所以你怎么写都写不进去,所以你必须先创建你要写入的plist; 你用这样初始化程序就能自己创建: NSMutableA ...
- 制作签名jar放置到前端资源目录下
给jar包打签名keytool -genkey -keystore myKeystore -alias jwstest查看签名信息jarsigner -keystore myKeystore data ...
- 56.纯 CSS 描述程序员的生活
原文地址:https://segmentfault.com/a/1190000015316996 感想:动画加延时,white-space: pre; 保留HTML p 中刻意留下的空白. HTML ...
- js分钟数转天-时-分
//js格式化分钟转为天.时.分 function formatMinutes(minutes) { )); ? Math.floor((minutes - day * ) / ) : Math.fl ...