Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- PYTHON
- 코로나19
- 데이콘
- 맥북
- gs25
- ChatGPT
- 더현대서울 맛집
- 금융문자분석경진대회
- hackerrank
- Docker
- ubuntu
- 프로그래머스 파이썬
- dacon
- Real or Not? NLP with Disaster Tweets
- Baekjoon
- 파이썬
- 프로그래머스
- leetcode
- programmers
- 캐치카페
- 자연어처리
- 백준
- SW Expert Academy
- AI 경진대회
- 편스토랑
- github
- Kaggle
- 우분투
- Git
- 편스토랑 우승상품
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1207. Unique Number of Occurrences (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 1207. Unique Number of Occurrences (Python)
솜씨좋은장씨 2020. 9. 23. 00:52728x90
반응형
Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.
Example 1:
Input: arr = [1,2,2,1,1,3]
Output: true
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1.
No two values have the same number of occurrences.
Example 2:
Input: arr = [1,2]
Output: false
Example 3:
Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
Output: true
Constraints:
- 1 <= arr.length <= 1000
- -1000 <= arr[i] <= 1000
Solution
from collections import Counter
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
cnt = Counter(arr)
cnt_list = [item[1] for item in cnt.items()]
set_list = list(set(cnt_list))
print(set_list)
if len(cnt_list) != len(set_list):
return False
return True
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 925. Long Pressed Name (Python) (0) | 2020.09.25 |
---|---|
[leetCode] 686. Repeated String Match (Python) (0) | 2020.09.24 |
[leetCode] 657. Robot Return to Origin (Python) (0) | 2020.09.22 |
[leetCode] 703. Kth Largest Element in a Stream (Python) (0) | 2020.09.21 |
[leetCode] 1189. Maximum Number of Balloons (Python) (0) | 2020.09.20 |
Comments