From 660833125d7e7d7e44da1d68deb53430640f6bc7 Mon Sep 17 00:00:00 2001 From: ironartisan Date: Sat, 7 Aug 2021 21:15:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=201207.=E7=8B=AC=E4=B8=80?= =?UTF-8?q?=E6=97=A0=E4=BA=8C=E7=9A=84=E5=87=BA=E7=8E=B0=E6=AC=A1=E6=95=B0?= =?UTF-8?q?python3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1207.独一无二的出现次数.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md index c1720430..32aa3c3a 100644 --- a/problems/1207.独一无二的出现次数.md +++ b/problems/1207.独一无二的出现次数.md @@ -100,7 +100,21 @@ class Solution { ``` Python: - +```python +class Solution: + def uniqueOccurrences(self, arr: List[int]) -> bool: + count = [0] * 2002 + for i in range(len(arr)): + count[arr[i] + 1000] += 1 # 防止负数作为下标 + freq = [False] * 1002 # 标记相同频率是否重复出现 + for i in range(2001): + if count[i] > 0: + if freq[count[i]] == False: + freq[count[i]] = True + else: + return False + return True +``` Go: JavaScript: