본문 바로가기
Codility

[Codility] Caterpillar Method : AbsDistinct

by paysmile 2021. 7. 16.

https://app.codility.com/programmers/lessons/15-caterpillar_method/abs_distinct/

 

AbsDistinct coding task - Learn to Code - Codility

Compute number of distinct absolute values of sorted array elements.

app.codility.com

 

int solution(vector<int> &A) {
    int sz = A.size();
    for(int i=0; i<sz; i++){
        A[i] = abs(A[i]);
    }
    sort(A.begin(),A.end());
    A.erase(unique(A.begin(),A.end()),A.end());

    return A.size();
}