Leetcode 1207. Unique Number of Occurrences

Posted SnailTyan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 1207. Unique Number of Occurrences相关的知识,希望对你有一定的参考价值。

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

1. Description

Unique Number of Occurrences

2. Solution

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

  • Version 1
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/

以上是关于Leetcode 1207. Unique Number of Occurrences的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode 1207. Unique Number of Occurrences

1207. Unique Number of Occurrences

添加unique约束

leetcode1207

unique()函数

unique()函数