LeetCode 217. Contains Duplicate

Contains Duplicate

public class Solution {
    public bool ContainsDuplicate(int[] nums) {
        HashSet<int> h = new HashSet<int>();
        foreach(int i in nums){
            if(h.Contains(i)) return true;
            h.Add(i);
        }
        return false;
    }
}

Leave a Reply

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