diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md index 377d9ebf..c1720430 100644 --- a/problems/1207.独一无二的出现次数.md +++ b/problems/1207.独一无二的出现次数.md @@ -77,6 +77,28 @@ public: Java: +```java +class Solution { + public boolean uniqueOccurrences(int[] arr) { + int[] count = new int[2002]; + for (int i = 0; i < arr.length; i++) { + count[arr[i] + 1000]++; // 防止负数作为下标 + } + boolean[] flag = new boolean[1002]; // 标记相同频率是否重复出现 + for (int i = 0; i <= 2000; i++) { + if (count[i] > 0) { + if (flag[count[i]] == false) { + flag[count[i]] = true; + } else { + return false; + } + } + } + return true; + } +} +``` + Python: Go: @@ -89,4 +111,3 @@ JavaScript: * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)