Hard-题目2：287. Find the Duplicate Number

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.

public class Solution {
public int findDuplicate(int[] nums) {
HashSet<Integer> set = new HashSet<Integer>();
for(int num : nums)
return num;
return -1;
}
}

6ms,beats 23.40%,众数1ms，28.98%
Cmershen的碎碎念：

http://blog.sina.com.cn/s/blog_a131087e0102vtb1.html中提到个很巧妙的two pointers解法，有待下次修正时认真研读。（大致是有重复元素时会迭代成环？）

［Leetcode］287. Find the Duplicate Number简单解法及解释 双指针复杂度O(n)

2016-01-01 11:34:20

leetcode 【287 Find the Duplicate Number】【Python】

2016-09-09 11:19:30

[leetcode 287]Find the Duplicate Number

2015-09-28 13:51:35

leetcode 287: Find the Duplicate Number

2015-09-29 08:29:12

LeetCode 287. Find the Duplicate Number 题解（C++）

2016-11-10 15:16:02

leetcode 287: Find the Duplicate Number(二分和List)

2018-06-27 21:39:12

LeetCode 287. Find the Duplicate Number（找重复数字）

2016-04-15 07:02:18

287. Find the Duplicate Number

2016-03-06 11:45:57

287. Find the Duplicate Number。

2018-01-26 00:07:04

leetcode 287. Find the Duplicate Number，数组中找重复的数

2016-03-27 21:09:43