287. Find the Duplicate Number

 class Solution {

public:

    int findDuplicate(vector<int>& nums) {

        map<int,int>m;

        for(int i=0;i<nums.size();i++){

            if(m[nums[i]]>=1)

                return nums[i];

            else {

                m[nums[i]]++;

            }

        }

        return -1;

    }

};

Comments

Popular posts from this blog

2161. Partition Array According to Given Pivot

2000. Reverse Prefix of Word

1769. Minimum Number of Operations to Move All Balls to Each Box