This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

LeetCode – Contains Duplicate – DEV Community


Given an integer array nums, return true if any worth seems a minimum of twice within the array, and return false if each factor is distinct.

Instance 1:
Enter: nums = [1,2,3,1]
Output: true

Instance 2:
Enter: nums = [1,2,3,4]
Output: false

Instance 3:
Enter: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true

Constraints:

1 <= nums.size <= 105
-109 <= nums[i] <= 109

Resolution:

class Resolution {
    public boolean containsDuplicate(int[] no) {
         if(no==null || no.size==0)
        return false;

    HashSet<Integer> set = new HashSet<Integer>();
    for(int i: no){
        if(!set.add(i)){
            return true;
        }
    }

    return false;

    }
}
Enter fullscreen mode

Exit fullscreen mode

Fore extra options LeetCode

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?