Solution using map C++


  • 0
    G
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
           map<int,int> m;
           m.clear();
           for(int i=0;i<nums.size();i++)
           {
               m[nums[i]]++;
           }
           map<int,int> ::iterator it;
           bool flag=false;
           for(it=m.begin();it!=m.end();++it)
           {
               if(it->second>=2)
               {
               flag=true;
               break;
               }
           }
           return flag;
        }
    };
    

Log in to reply
 

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