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 256b3b3

Browse files
committed
Create 1207-UniqueNumberOfOccurrences.py
1 parent c0ca05c commit 256b3b3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
"""
3+
CREATED AT: 2022年11月30日
4+
5+
URL: https://leetcode.com/problems/unique-number-of-occurrences/
6+
7+
GITHUB: https://github.com/Jiezhi/myleetcode
8+
9+
FileName: 1207-UniqueNumberOfOccurrences
10+
11+
Difficulty: Easy
12+
13+
Desc:
14+
15+
Tag:
16+
17+
See:
18+
19+
"""
20+
from tool import *
21+
22+
23+
class Solution:
24+
def uniqueOccurrences(self, arr: List[int]) -> bool:
25+
"""
26+
Runtime: 79 ms, faster than 21.81%
27+
Memory Usage: 13.9 MB, less than 72.74%
28+
1 <= arr.length <= 1000
29+
-1000 <= arr[i] <= 1000
30+
"""
31+
cnt = Counter(arr)
32+
return len(cnt.keys()) == len(set(cnt.values()))
33+
34+
35+
def test():
36+
assert Solution().uniqueOccurrences(arr=[1, 2, 2, 1, 1, 3])
37+
assert not Solution().uniqueOccurrences(arr=[1, 2])
38+
assert Solution().uniqueOccurrences(arr=[-3, 0, 1, -3, 1, 1, 1, -3, 10, 0])
39+
40+
41+
if __name__ == '__main__':
42+
test()

0 commit comments

Comments
(0)

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