[C++] Simple Solution O(n)


#1
int Solution::longestConsecutive(const vector<int> &A) {
    map<int,int> map;
    for(int x: A)
        map[x]++;
    int ans=0;
    for(auto it = map.begin();it!= map.end();it++)
    {
        it->second = map[it->first -1]+1;
        ans = max(ans,it->second);
    }
    return ans;
}