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

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones