diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md index afc93eda..1a7a0019 100644 --- a/problems/1207.独一无二的出现次数.md +++ b/problems/1207.独一无二的出现次数.md @@ -98,7 +98,8 @@ class Solution { ``` Python: -```python +```python +# 方法 1: 数组在哈西法的应用 class Solution: def uniqueOccurrences(self, arr: List[int]) -> bool: count = [0] * 2002 @@ -113,6 +114,26 @@ class Solution: return False return True ``` +```python +# 方法 2: map 在哈西法的应用 +class Solution: + def uniqueOccurrences(self, arr: List[int]) -> bool: + ref = dict() + + for i in range(len(arr)): + ref[arr[i]] = ref.get(arr[i], 0) + 1 + + value_list = sorted(ref.values()) + + for i in range(len(value_list) - 1): + if value_list[i + 1] == value_list[i]: + return False + + return True + +``` + + Go: JavaScript: