상세 컨텐츠

본문 제목

[LeetCode][Python] 1207. Unique Number of Occurrences

공부

by 근성 2024. 1. 17. 23:42

본문

https://leetcode.com/problems/unique-number-of-occurrences/description/?envType=daily-question&envId=2024-01-17

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

배열들의 갯수를 카운팅했을때,

카운팅의 갯수가 다를경우 True

같은경우 False를 반환한다.


Counter와 Set을 통해 끝낼 수 있다.

class Solution:
    def uniqueOccurrences(self, arr: List[int]) -> bool:
        count = Counter(arr)
        counter_count = []
        if len(set(count.values())) != len(count):
            return False
        else:
            return True

관련글 더보기

댓글 영역