We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1ef0f80 commit f35afcaCopy full SHA for f35afca
src/main/java/com/fishercoder/solutions/_645.java
@@ -1,6 +1,8 @@
1
package com.fishercoder.solutions;
2
3
import java.util.Arrays;
4
+import java.util.HashSet;
5
+import java.util.Set;
6
7
public class _645 {
8
public static class Solution1 {
@@ -22,4 +24,25 @@ public int[] findErrorNums(int[] nums) {
22
24
return result;
23
25
}
26
27
+
28
+ public static class Solution2 {
29
+ public int[] findErrorNums(int[] nums) {
30
+ Set<Integer> set = new HashSet();
31
+ boolean[] has = new boolean[nums.length];
32
+ int dup = -1;
33
+ for (int i = 0; i < nums.length; i++) {
34
+ has[nums[i] - 1] = true;
35
+ if (!set.add(nums[i])) {
36
+ dup = nums[i];
37
+ }
38
39
+ int dup2 = -1;
40
+ for (int i = 0; i < has.length; i++) {
41
+ if (!has[i]) {
42
+ dup2 = i + 1;
43
44
45
+ return new int[]{dup, dup2};
46
47
48
0 commit comments