Skip to content

Commit c5a57f3

Browse files
committed
Added Array Duplicates Medim
1 parent 974d17d commit c5a57f3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
left ++;
14+
}
15+
return answer;
16+
}
17+
}

0 commit comments

Comments
 (0)