Leetcode 1207. Unique Number of Occurrences

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Unique Number of Occurrences

2. Solution

解析:Version 1,先统计数字数量,再用mapset判断数量是否重复。

  • Version 1
1
2
3
4
5
6
7
8
9
10
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
stat = collections.Counter(arr)
temp = {}
for value in stat.values():
if value not in temp:
temp[value] = 1
else:
return False
return True

Reference

  1. https://leetcode.com/problems/unique-number-of-occurrences/
如果有收获,可以请我喝杯咖啡!