Tech

Distinct Numbers (CSES 1621)

Published
Published:
Table of Contents
CSES Problem Set — 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