c_cpp 找到数组中的第一个不同元素

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 找到数组中的第一个不同元素相关的知识,希望对你有一定的参考价值。

int find_first_distinct_element(vector<int>& A) {
    if(A.empty()) return -1;
    unordered_map<int, int> mp
    for(auto i : A)
        mp[i]++;
    for(auto i : A)
        if(mp[i] == 1) 
            return i;
    return -1;
}

以上是关于c_cpp 找到数组中的第一个不同元素的主要内容,如果未能解决你的问题,请参考以下文章