Skip to content

Commit ad73554

Browse files
committed
Runtime 1105 ms (Top 5.1%) | Memory 43.0 MB (Top 63.9%)
1 parent 6907953 commit ad73554

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int[] findErrorNums(int[] nums) {
3+
int n = nums.length;
4+
int dup = 0, miss = 0;
5+
6+
for (int i = 1; i <= n; i++) {
7+
int count = 0;
8+
for (int j = 0; j < n; j++) {
9+
if (nums[j] == i) count++;
10+
}
11+
12+
if (count == 2) dup = i;
13+
if (count == 0) miss = i;
14+
}
15+
16+
return new int[] {dup, miss};
17+
}
18+
}
19+
20+
// TC: O(n ^ 2), SC: O(1)

0 commit comments

Comments
 (0)