-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion56.java
More file actions
52 lines (43 loc) · 938 Bytes
/
Copy pathQuestion56.java
File metadata and controls
52 lines (43 loc) · 938 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
/*
* Question 56:
Given a sorted array of integers, remove duplicates such that each element
appears only once. Print the elements without duplicates.
Input:
nums = [1, 1, 2, 2, 3, 4, 4, 5]
Output:
[1, 2, 3, 4, 5]
*/
package com.nit_51_60;
import java.util.Arrays;
import java.util.stream.IntStream;
public class Question56 {
public static void main(String[] args) {
int temp=0;
int arr[]= {1, 1, 2, 2, 3, 4, 4, 5};
for(int i=0;i<arr.length-1;i++)
{
if(arr[i]==arr[i+1])
{
arr[i]=0;
}
}
for(int i=0;i<arr.length;i++)
{
for(int j=i;j<arr.length;j++)
{
if(arr[i]==0)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
// IntStream intStream = Arrays.stream(arr);
// intStream.distinct().forEach(System.out::println);
}
}