Problem 217

Posted by Ruizhi Ma on November 16, 2020

Solution URL

https://leetcode.com/submissions/detail/420902405/

代码

class Solution {
    public boolean containsDuplicate(int[] nums) {
        //ans: Solution
        //Time: O(N). for hashset, search and insert are contant time and these operation
        //does for n times. So the O(N)
        //Space: O(N)
        HashSet<Integer> set = new HashSet<>();
        for(int num: nums){
            if(set.contains(num)) return true;
            set.add(num);
        }

        return false;
    }
}