LeetCode 19. Remove Nth Node From End of List
来源:互联网 发布:八皇后问题递归c语言 编辑:程序博客网 时间:2024/06/10 23:22
LeetCode 19. Remove Nth Node From End of List
给定一个链表,删除倒数第n各元素。
例如 给定链表: 1->2->3->4->5, and n = 2.
删除倒数第n各元素之后,剩下 1->2->3->5.
解题要求只遍历一次。
主要是利用两个指针之间的路程差为n来解这道题。
public ListNode removeNthFromEnd(ListNode head,int n){ ListNode temp = head; ListNode result = head; int num = 0; while (head != null){ head = head.next; if(num > n){ temp = temp.next; } num++; } if(n == num) result = result.next; else temp.next = temp.next.next; return result; }
阅读全文
0 0
- 19. Remove Nth Node From End of List leetcode list
- [LeetCode]19.Remove Nth Node From End of List
- LeetCode 19. Remove Nth Node From End of List
- 19. Remove Nth Node From End of List Leetcode Python
- LeetCode --- 19. Remove Nth Node From End of List
- LeetCode 19.Remove Nth Node From End of List
- [Leetcode] 19. Remove Nth Node From End of List
- [leetcode] 19.Remove Nth Node From End of List
- <LeetCode OJ> 19. Remove Nth Node From End of List
- 19. Remove Nth Node From End of List LeetCode
- leetcode 19. Remove Nth Node From End of List
- [LeetCode OJ] 19. Remove Nth Node From End of List
- LeetCode 19. Remove Nth Node From End of List
- Leetcode:19. Remove Nth Node From End of List(JAVA)
- leetcode 19. Remove Nth Node From End of List
- Leetcode 19. Remove Nth Node From End of List
- 【LeetCode】19. Remove Nth Node From End of List
- leetcode 19.Remove Nth Node From End of List
- Sass安装
- 标准W3C盒子模型和IE盒子模型
- C++实现简单二叉树
- 机器学习中各种距离计算
- linux (centOS) 网络链接配置(windows10)
- LeetCode 19. Remove Nth Node From End of List
- Java笔试题解(6)
- Android屏幕适配解决方案
- iOS开发isa 指针 与 runtime 机制
- poj3087 Shuffle'm Up
- Ubuntu上安装Bitcoin Core
- java数组常见的排序——选择排序和冒泡排序
- Python学习笔记(六)— 函数
- Shell脚本——时间同步