Distinct Numbers (CSES 1621)

Problem 1621 of 2 · Sorting And Searching

Table of Contents
Chapters

Problem Link: Distinct Numbers

Approach

Put all values into a set and return its size.

Solution

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    set<int> s;
    while (n--) { int x; cin >> x; s.insert(x); }
    cout << s.size();
}
Support this post Sponsor