Skip to content

Commit cc291fd

Browse files
authored
645
1 parent 12d0f1a commit cc291fd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

645. Set Mismatch.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Runtime 3ms
2+
// Beats 81.72%
3+
4+
// Memory 45.46MB
5+
// Beats 42.36%
6+
7+
8+
9+
class Solution {
10+
public int[] findErrorNums(int[] nums) {
11+
boolean[] exist = new boolean[nums.length];
12+
int d = 0, l = 0;
13+
14+
Arrays.fill(exist, true);
15+
16+
for(int i:nums){
17+
if(exist[i-1] == false){
18+
d=i;
19+
}
20+
exist[i-1]=false;
21+
}
22+
23+
for(int i = 0; i < nums.length; i++) {
24+
if(exist[i]) {
25+
l= i+1;
26+
break;
27+
}
28+
}
29+
30+
return new int[]{d,l};
31+
}
32+
}

0 commit comments

Comments
 (0)