LeetCode:Remove Nth Node From End of List
来源:互联网 发布:网络电影数据分析 编辑:程序博客网 时间:2024/06/05 06:11
题目链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/
题目介绍:删除链表倒数第n个结点
解题思路:先遍历一边链表得出该链表的长度,然后计算倒数第n个结点前的结点个数,然后删除链表倒数第n个结点。
代码如下:
class Solution {public: ListNode* removeNthFromEnd(ListNode* head, int n) { int len = 0; ListNode* node = head; while (node != NULL) { node = node->next; len++; } int f = len-n-1; if (f < 0) { head = head->next; } else { ListNode* a = head; while (f > 0) { a = a->next; f--; } a->next = a->next->next; } return head; }};
阅读全文
0 0
- LeetCode[Linked List]: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- leetcode 40: Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- Leetcode 19 Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- [LeetCode]Remove Nth Node From End of List
- LeetCode-Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- LeetCode 19: Remove Nth Node From End of List
- LeetCode - Remove Nth Node From End of List
- LeetCode | Remove Nth Node From End of List
- leetcode之Remove Nth Node From End of List
- js优化之惰性加载函数
- AI的伦理挑战
- Part-Time Jobs
- 线性判别分析(Linear Discriminant Analysis, LDA) 学习笔记 + matlab实现
- oracle本机能连外部访问不了
- LeetCode:Remove Nth Node From End of List
- 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍 一、pandas 是什么 pandas 是基于 NumPy 的一个 Python 数据分析包,主
- Java中输入输出文件流操作
- 织梦后台在谷歌内核浏览器(如360)下的窜位问题
- React Native参考
- 2017年乌镇互联网大会,互联网大佬们齐聚首
- UE主叫与被叫的基本流程(WCDMA)
- LVS集群部署及故障排查
- Read Time