From b6424893b3bfc25b8f4824f5ba994641e708b176 Mon Sep 17 00:00:00 2001 From: posper Date: Wed, 28 Jul 2021 15:25:16 +0800 Subject: [PATCH] =?UTF-8?q?1207.=E7=8B=AC=E4=B8=80=E6=97=A0=E4=BA=8C?= =?UTF-8?q?=E7=9A=84=E5=87=BA=E7=8E=B0=E6=AC=A1=E6=95=B0=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0Java=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1207.独一无二的出现次数.md | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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)
-