Distinct

problem

solution

option 1 - set

1
2
3
4
5
6
7
8
9
10
11
12
13
// you can use includes, for example:
// #include <algorithm>

// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;

#include<unordered_set>
int solution(vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
unordered_set<int> s;
for(int a:A) s.insert(a);
return s.size();
}

option 2 -

1

analysis

  • optino 1
    • time complexity O(n)
    • space complexity O(n)