forked from coder2hacker/Explore-open-source
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveDuplicate_sortedarray.java
More file actions
55 lines (41 loc) · 931 Bytes
/
RemoveDuplicate_sortedarray.java
File metadata and controls
55 lines (41 loc) · 931 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
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
static int remDups(int arr[], int n)
{
int temp[] = new int[n];
temp[0] = arr[0];
int res = 1;
for(int i = 1; i < n; i++)
{
if(temp[res - 1] != arr[i])
{
temp[res] = arr[i];
res++;
}
}
for(int i = 0; i < res; i++)
{
arr[i] = temp[i];
}
return res;
}
public static void main(String args[])
{
int arr[] = {10, 20, 20, 30, 30, 30}, n = 6;
System.out.println("Before Removal");
for(int i = 0; i < n; i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
n = remDups(arr, n);
System.out.println("After Removal");
for(int i = 0; i < n; i++)
{
System.out.print(arr[i]+" ");
}
}
}