Skip to content

Commit 3a98060

Browse files
refactor 287
1 parent e5ec0ad commit 3a98060

File tree

1 file changed

+6
-15
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-15
lines changed

src/main/java/com/fishercoder/solutions/_287.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,12 @@
33
import java.util.HashSet;
44
import java.util.Set;
55

6-
/**
7-
* 287. Find the Duplicate Number
8-
*
9-
* Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive),
10-
* prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
11-
*
12-
Note:
13-
You must not modify the array (assume the array is read only).
14-
You must use only constant, O(1) extra space.
15-
Your runtime complexity should be less than O(n2).
16-
There is only one duplicate number in the array, but it could be repeated more than once.
17-
18-
*/
196
public class _287 {
207

218
public static class Solution1 {
22-
/**no-brainer, used O(n) space*/
9+
/**
10+
* no-brainer, used O(n) space
11+
*/
2312
public int findDuplicate(int[] nums) {
2413
Set<Integer> set = new HashSet<>();
2514
int dup = 0;
@@ -34,7 +23,9 @@ public int findDuplicate(int[] nums) {
3423
}
3524

3625
public static class Solution2 {
37-
/** O(1) space */
26+
/**
27+
* O(1) space
28+
*/
3829
public int findDuplicate(int[] nums) {
3930
int slow = 0;
4031
int fast = 0;

0 commit comments

Comments
 (0)