-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveDuplicateFromArray.java
More file actions
43 lines (31 loc) · 750 Bytes
/
RemoveDuplicateFromArray.java
File metadata and controls
43 lines (31 loc) · 750 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
36
37
38
39
40
41
42
43
import java.util.Arrays;
class RemoveDuplicateFromArray
{
public static int removeDuplicateFromArray(int[] arr,int length){
if(length == 0 || length == 1){
return length;
}
int j = 0;
int temp[] = new int[length];
for(int i = 0 ; i < length - 1; i++){
if(arr[i] != arr[i+1]){
temp[j++] = arr[i];
}
}
temp[j++] = arr[length - 1];
for(int i = 0 ; i < j ; i++){
arr[i] = temp[i];
}
return j;
}
public static void main(String[] args)
{
int[] arr = {1,2,3,4,5,6,5,6};
Arrays.sort(arr);
int len = arr.length;
int length = removeDuplicateFromArray(arr,len);
for(int i = 0 ; i < length ; i++){
System.out.print(arr[i]);
}
}
}