-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray2.java
More file actions
35 lines (31 loc) · 890 Bytes
/
Array2.java
File metadata and controls
35 lines (31 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.HashSet;
public class Array2{
// 26. Remove Duplicates from Sorted Array
public int removeDuplicates(int[] nums) {
int idx=0;
for(int i=0; i<nums.length; i++){
while(nums.length>i+1 && nums[i]==nums[i+1]){
i++;
}
nums[idx]= nums[i];
idx++;
}
return idx;
}
//Find all repeating elements in an array
public static void findRepeatingEle(int[] arr){
HashSet<Integer> h = new HashSet<>();
for(int i=0; i<arr.length; i++){
if(!h.contains(arr[i])){
h.add(arr[i]);
}else{
System.out.print(arr[i]+" ");
}
}
}
public static void main(String[] args) {
int Arr[] = {1,1,2,3,4,4,5,2};
int arr2[] = {1,1,0};
findRepeatingEle(arr2);
}
}