1. 问题描写叙述

  在一个给定的数组中,推断是否含有反复的数。


2. 方法与思路

  非常easy的一个题目。直接hash推断就可以,没有难度。
  

class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        if(nums.size() <= 0) return false;

        unordered_map<int,int> mp;
        for( auto &i :nums)
        {    
            if(mp.find(i) != mp.end() && mp[i])
                return true;
            mp[i] = 1;
        }
        return false;
    }
};

相关文章:

  • 2022-12-23
  • 2021-12-07
  • 2021-08-10
  • 2021-12-06
  • 2022-02-11
猜你喜欢
  • 2021-09-12
  • 2022-03-01
  • 2021-12-20
  • 2021-08-24
  • 2021-12-11
相关资源
相似解决方案