MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / solve

Function solve

LeetCode_problems/First Missing Positive/Solution.cpp:4–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4int solve(vector<int>& a) {
5 int i=1;
6 //Copy array into unordered_set
7 unordered_set<int> us(a.begin(), a.end());
8 while(i <= us.size()){
9 //Increment i by 1 and search in set. Searching is O(1)
10 if (us.find(i) == us.end())
11 break;
12 ++i;
13 }
14 //if i is not found return i.
15 return i;
16}
17int main() {
18 int t;
19 cin>>t;

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected