You are viewing a single comment's thread. Return to all comments →
import java.util.*; public class Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int []a = new int[n]; int count = 0; for(int i=0;i<n;i++) { a[i] = s.nextInt() ; } int freq[] = new int[101]; for(int i=0;i<n;i++) { int asc = a[i]; freq[asc]++; } for(int i=0;i<101;i++) { if(freq[i]>=1 || freq[i]%2==0) { count = count+freq[i]/2; } else if((freq[i]%2)!=0) { count = count+freq[i]%2; } } System.out.print(count); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →