ashu.835 arr = list(map(int,input().split())) a1 = [] for i in range(0, len(arr)): if arr[i] not in a1: a1.append(arr[i]) print(a1) Log in to Reply
Aqib solution: import java.util.*; public class RemoveReppeatedElements { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ans=0; int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=sc.nextInt(); Arrays.sort(arr); for(int i=0;i<arr.length-1;i++) { if(arr[i]!=arr[i+1]) System.out.print(arr[i]+" "); } System.out.print(arr[arr.length-1]); } } Log in to Reply
arr = list(map(int,input().split()))
a1 = []
for i in range(0, len(arr)):
if arr[i] not in a1:
a1.append(arr[i])
print(a1)
solution:
import java.util.*;
public class RemoveReppeatedElements {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int ans=0;
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
Arrays.sort(arr);
for(int i=0;i<arr.length-1;i++)
{
if(arr[i]!=arr[i+1])
System.out.print(arr[i]+" ");
}
System.out.print(arr[arr.length-1]);
}
}