We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 974d17d commit c5a57f3Copy full SHA for c5a57f3
1 file changed
Medium/03_03_2020_array_duplicates.java
@@ -0,0 +1,17 @@
1
+// Time: O(n) | Space: O(d) where d is te numbher of duplicates that we found.
2
+import java.util.*;
3
+class Solution {
4
+ public List<Integer> findDuplicates(int[] nums) {
5
+ Arrays.sort(nums);
6
+ ArrayList<Integer> answer = new ArrayList<>();
7
+ int left = 0;
8
+ while (left < nums.length - 1) {
9
+ if (nums[left] == nums[left + 1]) {
10
+ answer.add(nums[left]);
11
+ left ++;
12
+ }
13
14
15
+ return answer;
16
17
+}
0 commit comments