Leetcode 1207. Unique Number of Occurrences

2021-07-14 13:53:46 浏览数 (1)

1. Description

2. Solution

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

  • Version 1
代码语言:javascript复制
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/

0 人点赞