public class Solution {
public int FindDuplicate(int[] nums) {
if (nums.Count() > )
{
int slow = nums[];
int fast = nums[nums[]];
while (slow != fast)
{
slow = nums[slow];
fast = nums[nums[fast]];
} fast = ;
while (fast != slow)
{
fast = nums[fast];
slow = nums[slow];
}
return slow;
}
return -;
}
}

https://leetcode.com/problems/find-the-duplicate-number/#/description

leetcode287的更多相关文章

  1. [Swift]LeetCode287. 寻找重复数 | Find the Duplicate Number

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  2. leetcode287 Find the Duplicate Number

    思路: 转换成链表之后使用floyed判环法.转换之后重复的那个数字是唯一一个有多个前驱和一个后继的节点,因此是环的起始节点. 实现: class Solution { public: int fin ...

  3. LeetCode 287

    Find the Duplicate Number Given an array nums containing n + 1 integers where each integer is betwee ...

  4. 2017-3-9 leetcode 283 287 289

    今天操作系统课,没能安心睡懒觉23333,妹抖龙更新,可惜感觉水分不少....怀念追RE0的感觉 =================================================== ...

随机推荐

  1. 返回指针的函数 ------ 指针函数(pointer function)

    指针函数: 其本质是一个函数, 其函数返回值为某一类型的指针. 定义形式: 类型 *指针变量名(参数列表): 例如: int *p(int i,int j); p是一个函数名,该函数有2个整形参数,返 ...

  2. 8--Python入门--函数

    函数基本框架如下([]中的内容表示是或选的,可以不写):def 函数名(参数): ['''函数说明文档'''] 函数主体 [return 返回对象] 函数小例子 #我们先定义一个函数 def find ...

  3. L2-020. 功夫传人*

    L2-020. 功夫传人 参考博客 #include<vector> #include<cstring> #include<algorithm> using nam ...

  4. I/O简介

    用户空间是常规进程所在区域.JVM就是常规进程,驻守于用户空间.用户空间是非特权区域,在该区域执行的代码不能直接访问硬件设备. 内核空间是操作系统所在区域.内核代码有特别的权利:它能与设备控制器通讯, ...

  5. webpack配置文件--(loader)

    这篇写的很详细 https://segmentfault.com/a/1190000012718374#articleHeader9 主要的配置项: test:必须 匹配需要处理的文件的扩展名 use ...

  6. shell批处理文件,并将运算结果返回

    问题背景是这样的:别人用C++写了一个算法,算法内部比较复杂,但是呢,对于编译好的文件用起来比较方便,比如在linux终端,my_program 1.png 2.txt这样就可以用,但是这样只能够输入 ...

  7. 集群相关、用keepalived配置高可用集群

    1.集群相关 2.keepalived相关 3.用keepalived配置高可用集群 安装:yum install keepalived -y   高可用,主要是针对于服务器硬件或服务器上的应用服务而 ...

  8. 2018.5.2 file结构体

    f_flags,File Status Flag f_pos,表示当前读写位置 f_count,表示引用计数(Reference Count): dup.fork等系统调用会导致多个文件描述符指向同一 ...

  9. hello1源码解析

    1.选择hello1文件夹并单击“打开项目” 2.展开网页节点,双击index.xhtml文件在编辑器中查看它 index.xhtml文件是facelets应用程序的默认登录页,在典型的facelet ...

  10. Yii2事件驱动的运行机制

    最近一段时间正在作个一个项目,这个项目会系统逻辑比较复杂,使用PHP Yii2,使用事件驱动机制进行研发,下面就最近研究事件驱动机制的使用作以下总结: 流程如下: 1.要创建含有事件注入的类,一般这样 ...