Find unique numbers in array

后端 未结 8 1136
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 20:14

Well, I have to find how many different numbers are in an array.

For example if array is: 1 9 4 5 8 3 1 3 5

The output should be 6, because 1,9,4,5,8,3 are uniqu

8条回答
  •  死守一世寂寞
    2021-02-04 20:40

    We can use C++ STL vector in this program .

      int main() 
      {
        int a[] = {1, 9, 4, 5, 8, 3, 1, 3, 5};
        vectorv(a, a+9);
    
        sort(v.begin(), v.end()); 
        v.erase(unique(v.begin(), v.end()), v.end()); 
    
        cout<

提交回复
热议问题