Editorial for Distinct Numbers
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Python
N = int(input())
numbers = list(map(int, input().split()))
unique_count = len(set(numbers))
print(unique_count)
Java
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
Set<Integer> uniqueNumbers = new HashSet<>();
for (int i = 0; i < N; i++) {
int num = sc.nextInt();
uniqueNumbers.add(num);
}
System.out.println(uniqueNumbers.size());
}
}
C++
#include <iostream>
#include <set>
using namespace std;
int main() {
int N;
cin >> N;
set<int> uniqueNumbers;
for (int i = 0; i < N; i++) {
int num;
cin >> num;
uniqueNumbers.insert(num);
}
cout << uniqueNumbers.size() << endl;
return 0;
}
Comments