# 287. 寻找重复数

2018-07-08

``````输入: [1,3,4,2,2]

``````

``````输入: [3,1,3,4,2]

``````

``````不能更改原数组（假设数组是只读的）。

``````

Floyd判圈算法

``````public int findDuplicate(int[] nums) {
int slow = 0;
int fast = 0;
// 找到快慢指针相遇的地方
do {
//龟走一步
slow = nums[slow];
//兔走二步
fast = nums[nums[fast]];
} while (slow != fast);
int find = 0;
// 用一个新指针从头开始，直到和慢指针相遇
while (find != slow) {
slow = nums[slow];
find = nums[find];
}
return find;
}
``````
{"ft_lang_label":"__label__zh","ft_lang_prob":0.92757714,"math_prob":0.9984463,"size":1019,"snap":"2021-43-2021-49","text_gpt3_token_len":821,"char_repetition_ratio":0.08571429,"word_repetition_ratio":0.0,"special_character_ratio":0.3395486,"punctuation_ratio":0.17486338,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95377153,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-07T08:33:37Z\",\"WARC-Record-ID\":\"<urn:uuid:e54479a7-96d2-4a70-a772-4126e71ed086>\",\"Content-Length\":\"21982\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:80038498-7def-443f-86ee-5d8b62bc06ce>\",\"WARC-Concurrent-To\":\"<urn:uuid:7e79aeb2-db4a-4611-9ef7-bca514456cf6>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://zhangluncong.com/2018/07/08/findDuplicate/\",\"WARC-Payload-Digest\":\"sha1:EHC2QLAFWQV3A6N4TLARMGRA6NP36KWN\",\"WARC-Block-Digest\":\"sha1:3KISPUYKWG3GQX6RHBPMGWLW5P663YCS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363337.27_warc_CC-MAIN-20211207075308-20211207105308-00632.warc.gz\"}"}