-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
35 lines (25 loc) · 785 Bytes
/
solution.java
File metadata and controls
35 lines (25 loc) · 785 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
public class solution {
public static void removeduplicates(int arr[]){
if (arr.length <=1) {
return ;
}
int newarr[] = new int[arr.length];
int j = 0;
for(int i = 0; i < arr.length-1; i++){
if(arr[i] != arr[i+1]){
newarr[j++] = arr[i];
}
}
newarr[j++] = arr[arr.length-1];
for (int i = 0; i < newarr.length; i++) {
arr[i] = newarr[i];
}
for(int n: newarr){
System.out.print(n+" ");
}
}
public static void main(String[] args){
int arr[] = {1,1,2,3,3,3,5,5,5};
removeduplicates(arr);
}
}