Grind75
문제로

풀이2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Map<Integer, Integer> numsMap = new HashMap();

        for(int num : nums) {
            numsMap.put(num, numsMap.getOrDefault(num, 0) + 1);
            if(numsMap.get(num) > 1) return true;
        }

        return false;
    }
}

image

풀이2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Set<Integer> numsSet = new HashSet();

        for(int num : nums) {
            if(numsSet.add(num)) ;
            else return true;
        }

        return false;
    }
}

image