We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d119cdf commit 9c0ea54Copy full SHA for 9c0ea54
src/main/java/com/fishercoder/solutions/_645.java
@@ -45,4 +45,24 @@ public int[] findErrorNums(int[] nums) {
45
return new int[]{dup, dup2};
46
}
47
48
+
49
+ public static class Solution3 {
50
+ public int[] findErrorNums(int[] nums) {
51
+ int[] arr = new int[nums.length];
52
+ Set<Integer> set = new HashSet<>();
53
+ int[] result = new int[2];
54
+ for (int i = 0; i < nums.length; i++) {
55
+ arr[i] = i + 1;
56
+ if (!set.add(nums[i])) {
57
+ result[0] = nums[i];
58
+ }
59
60
61
+ if (!set.contains(i + 1)) {
62
+ result[1] = i + 1;
63
64
65
+ return result;
66
67
68
0 commit comments