Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?算法思路1:快慢指针,当两个指针相遇,则表示有环,...
分类:
其他好文 时间:
2014-07-19 18:38:30
阅读次数:
198
Linked List Cycle IIGiven a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without u...
分类:
其他好文 时间:
2014-07-19 18:18:51
阅读次数:
270
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1
/ 2 5
/ \ 3 4 6
The flattened tree should look like:
1...
分类:
其他好文 时间:
2014-07-19 11:47:54
阅读次数:
168
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
分类:
其他好文 时间:
2014-07-19 00:24:36
阅读次数:
170
Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No...
分类:
其他好文 时间:
2014-07-18 00:32:24
阅读次数:
271
刚才写了k个,顺手写个2个的,在链表的归并排序中很有用,效率非常好 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next;...
分类:
其他好文 时间:
2014-07-16 17:42:41
阅读次数:
275
Problem: Implement a function to check if a singly linked list is a palindrome.思路:最简单的方法是 Reverse and compare.另外一种非常经典的办法是用 Recursive 的思路,把一个list看成这种形...
分类:
其他好文 时间:
2014-07-16 17:41:23
阅读次数:
188
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1-...
分类:
其他好文 时间:
2014-07-16 17:30:52
阅读次数:
230
题目分析见这里
class Solution:
# @param head, a ListNode
# @return a list node
def detectCycle(self, head):
if None == head or None == head.next:
return None
pfast = ...
分类:
编程语言 时间:
2014-07-16 17:18:53
阅读次数:
248
class Solution:
# @param head, a ListNode
# @return a boolean
def hasCycle(self, head):
if None == head or None == head.next:
return False
pfast = head
...
分类:
编程语言 时间:
2014-07-16 09:50:21
阅读次数:
271