题解 | 序列中整数去重

序列中整数去重

https://www.nowcoder.com/practice/6564a2f6e70f4153ad1ffd58b2b28490

#include<iostream>
#include<vector>
//#include<unordered_set>
//本来想用这个来做,但是unordered_set不是维持原来的位置,而是随机顺序输出的
//如果在本地跑,可能可以按原来的数组顺序,但是牛客的不行
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    vector<ll>nums;
    vector<ll>arr(n * n, 0);//用输入的数字来作为索引,来记录是否重复,如果>1就是有了
    for (int i = 0; i < n; i++) {
        ll p = 0;
        cin >> p;
        if (arr[p] == 0) {
            nums.push_back(p);
            arr[p]++;
        }
    }
    for (ll u : nums) {
        cout << u << " ";
    }
    return 0;
}

全部评论

相关推荐

累死的一条狗:***一人顶10人那你给我发10个人的工资总和吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务