use unordered_map


  • 0
    W


    class Solution {
    public:
    bool containsDuplicate(vector<int>& nums) {
    unordered_map<int,int> mp;
    for(int i=0;i<nums.size();i++){
    if(++mp[nums[i]]>=2){
    return true;
    }
    }
    return false;
    }
    };


  • 0

    @wqkant Hi! Could you please format your code properly by surrounding your code with 3 backticks?

    Like this:

    ```
    Your code here
    ```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.