视频讲解  http://v.youku.com/v_show/id_XMTY1MTMzNjAyNA==.html (1)定义两个指针 ListNode fast = head; ListNode slow = head; (2)将快指针向前移动N步 (3.1)判断此时快指针是否已经到达尽头,如果是,头节点就是要删除的节点,返回head.next. (3.2)将快慢两个指针同时以相同的速度往前移动,当快指针走到尽头的时候,慢指针的下一个位置就是倒数第N个节点,将慢指针next指向next.nex…
给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 1->2->3->5. 说明: 给定的 n 保证是有效的. 进阶: 你能尝试使用一趟扫描实现吗? 方法一: 两次遍历,第一次求长度. 方法二: 一次遍历, first指针和second指针中间隔了n个节点,second ->next就是要删除的节点.当要删除的倒数长度和链表的长度相同时…
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the va…
Remove Nth Node From End of List Total Accepted: 46720 Total Submissions: 168596My Submissions Question Solution  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,…
1.合并两个排好序的list Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 2.删除list倒数第n个元素 Remove Nth Node From End of List Given a linked list,…
leetcode-algorithms-19 Remove Nth Node From End of List Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the…
61. Rotate List(M) Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ->->->->->NULL and k = , ->->->->->NULL. Total Accepted: 102574 Total Submissions: 423333 Difficulty: Medi…
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 这个是书的地址: https://hk029.gitbooks.io/leetbook/ 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…
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. 4Sum Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: The solution set must not contain duplicate quadruplets. Fo…