添加新方法

This commit is contained in:
Logen
2023-02-20 22:30:01 -06:00
parent 3c3a623b8a
commit 0b3e4aed92

View File

@ -99,6 +99,7 @@ class Solution {
Python Python
```python ```python
# 方法 1: 数组在哈西法的应用
class Solution: class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool: def uniqueOccurrences(self, arr: List[int]) -> bool:
count = [0] * 2002 count = [0] * 2002
@ -113,6 +114,26 @@ class Solution:
return False return False
return True 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 Go
JavaScript JavaScript