# LeetCode.1207-唯一的元素出现次数(Unique Number of Occurrences)

## 看题和准备

• 1 <= arr.length <= 1000
• -1000 <= arr[i] <= 1000

## 第一种解法

``````public boolean uniqueOccurrences(int[] arr) {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int num : arr) {
map.put(num, map.getOrDefault(num, 0)+1);
}
Set<Integer> set = new HashSet<Integer>();
for (Integer count : map.values()) {
if (set.contains(count)) {
return false;
}
}
return true;
}
``````

## 第二种解法

``````public boolean uniqueOccurrences2(int[] arr) {
int[] count = new int[2001];
for (int num : arr) {
count[num+1000]++;
}
int[] count2 = new int[2001];
for (int con : count) {
if (con != 0) {
count2[con]++;
if (count2[con] >= 2) {
return false;
}
}
}
return true;
}
``````

## 第三种解法

``````public boolean uniqueOccurrences3(int[] arr) {
int[] count = new int[2001];
for (int num : arr) {
count[num+1000]++;
}
boolean[] flag = new boolean[2001];
for (int con : count) {
if (con > 0) {
if (flag[con]) {
return false;
} else {
flag[con] = true;
}
}
}
return true;
}
``````