mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 04:54:51 +08:00
添加新方法
This commit is contained in:
@ -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:
|
||||||
|
Reference in New Issue
Block a user