Sort a linked list using insertion sort.题目意思是用插入排序对单链表进行排序,做法是返回一个新的单链表,每次插入的时候都添加一个新建的节点。/** * Definition for singly-linked list. * public class List...
分类:
其他好文 时间:
2014-09-13 15:54:15
阅读次数:
233
Sort a linked list inO(nlogn) time using constant space complexity.归并排序的基本思想是:找到链表的middle节点,然后递归对前半部分和后半部分分别进行归并排序,最后对两个以排好序的链表进行Merge。/** * Definitio...
分类:
其他好文 时间:
2014-09-13 13:15:45
阅读次数:
155
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 1 /** 2 * Definition for singly-linked l....
分类:
其他好文 时间:
2014-09-11 22:18:12
阅读次数:
311
1、题目Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?2、思路设置两个指针,一个每次走一步,另一个每次走两步。走两步的一定会追上走...
分类:
其他好文 时间:
2014-09-11 19:04:32
阅读次数:
223
[leetcode]Reverse Linked List II...
分类:
其他好文 时间:
2014-09-10 12:36:40
阅读次数:
220
Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note...
分类:
其他好文 时间:
2014-09-09 18:23:49
阅读次数:
222
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?算法:...
分类:
其他好文 时间:
2014-09-09 11:30:08
阅读次数:
188
public class Solution { public ListNode detectCycle(ListNode head) { ListNode slow = head; ListNode fast = head; boolean hasCy...
分类:
其他好文 时间:
2014-09-09 11:13:48
阅读次数:
204
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.难度70,与Convert Sorted Array to Binary Sear...
分类:
其他好文 时间:
2014-09-08 06:26:16
阅读次数:
263