Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b3e4ae

Browse files
添加新方法
1 parent 3c3a623 commit 0b3e4ae

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

‎problems/1207.独一无二的出现次数.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class Solution {
9898
```
9999

100100
Python:
101-
```python
101+
```python
102+
# 方法 1: 数组在哈西法的应用
102103
class Solution:
103104
def uniqueOccurrences(self, arr: List[int]) -> bool:
104105
count = [0] * 2002
@@ -113,6 +114,26 @@ class Solution:
113114
return False
114115
return True
115116
```
117+
```python
118+
# 方法 2: map 在哈西法的应用
119+
class Solution:
120+
def uniqueOccurrences(self, arr: List[int]) -> bool:
121+
ref = dict()
122+
123+
for i in range(len(arr)):
124+
ref[arr[i]] = ref.get(arr[i], 0) + 1
125+
126+
value_list = sorted(ref.values())
127+
128+
for i in range(len(value_list) - 1):
129+
if value_list[i + 1] == value_list[i]:
130+
return False
131+
132+
return True
133+
134+
```
135+
136+
116137
Go:
117138

118139
JavaScript:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /