Unique Number of Occurrences
给一个数组, 问里面的数字的个数是不是唯一. counting问题.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
class Solution { public boolean uniqueOccurrences(int[] arr) { Map<Integer, Integer> map = new HashMap<>(); for(int n : arr) map.put(n, map.getOrDefault(n, 0)+1); Map<Integer, Boolean> check = new HashMap<>(); for(int v : map.values()) { if(check.containsKey(v)) return false; check.put(v, true); } return true; } } |