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