题意:给定一个单链表,判断该链表中是否存在环,如果存在,返回环开始的节点
思路:
1.定义两个指针,快指针fast每次走两步,慢指针s每次走一次,如果它们在非尾结点处相遇,则说明存在环
2.若存在环,设环的周长为r,相遇时,慢指针走了 slow步,快指针走了 2s步,快指针在环内已经走了 n环,
则有等式 2s = s + nr => s = nr
3.在相遇的时候,另设一个每次走一步的慢指针slow2从链表开头往前走。因为 s = nr,所以两个慢指针会在环的开始点相遇
复杂度:时间O(n)
struct...
分类:
其他好文 时间:
2014-08-30 23:07:40
阅读次数:
187
Problem Description:
The set [1,2,3,…,n] contains a total
of n! unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):...
分类:
其他好文 时间:
2014-08-30 17:49:39
阅读次数:
171
烃类蒸汽转化炉的炉膛截面评级程序REFORM-3PC.V7.0+FRNC-5PC.V8.0 通用加热炉工艺计算软件KBC Petro-SIM Suite v4.0 SP2-ISO 1CD(炼油工艺流程模拟软件)FRNC-5PC.V8.0 通用加热炉工艺计算软件CAESAR II 2013 R1 v....
分类:
其他好文 时间:
2014-08-30 11:04:29
阅读次数:
296
方式1:#!/usr/bin/env python#-*- encoding: utf-8 -*-def permutations(iterable, r=None): # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC...
分类:
编程语言 时间:
2014-08-30 09:54:29
阅读次数:
328
There is a fire in LTR ’ s home again. The fire can destroy all the things in
t seconds, so LTR has to escape in t seconds. But there are some jewels in LTR ’ s rooms, LTR love jewels very much so h...
分类:
其他好文 时间:
2014-08-29 22:45:58
阅读次数:
308
leetcode上有四道关于移除有序序列中重复数字的题目,其中两道为数组结构,两道为链表结构,分别为:
(1)Remove Duplicates from sorted array I:移除一个有序数组中的重复数字,并且返回新数组的大小。
(2)Remove Duplicates from sorted array II:移除一个有序数组中的重复数字,并且返回新数组的大小,和上道题目不同的是每...
分类:
其他好文 时间:
2014-08-29 18:24:28
阅读次数:
289
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
Unique Paths II
Total Accepted: 13655 Total
Submissions: 49081My Submissions
Follow up for "Unique Paths":
Now consider i...
分类:
其他好文 时间:
2014-08-29 16:12:34
阅读次数:
236
全排列在leetcode Permutations Permutations|| 两道题目上的实现。...
分类:
其他好文 时间:
2014-08-29 13:08:38
阅读次数:
110
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-08-29 12:44:37
阅读次数:
256
这题比HDU4009要难一些。做了4009,大概知道了最小树形图的解法。拿到这题,最直接的想法是暴力。n个点试过去,每个都拿来做一次根。最后WA了,估计是超时了。(很多题都是TLE说WA,不断修改代码也看不出来错哪了)。 网上的正解是添加一个虚拟根(树根),使得它与n个点都有边相连。HDU40...
分类:
其他好文 时间:
2014-08-28 22:27:56
阅读次数:
490