일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 30분
- Daily Challenge
- 개발자
- 운동
- 매일
- leetcode
- 링피트
- 프로젝트
- 미드시청
- 읽기
- English
- Problem Solving
- 영어원서읽기
- 월간
- 화상영어
- 스탭퍼
- realclass
- 리얼 클래스
- 잡생각
- Writing
- 만화도
- 영어공부
- 사이드
- FIT XR
- 10분
- 뭐든
- 괜찮음
- 3줄정리
- 쓰릴오브파이트
- 파비최
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/reduce-array-size-to-the-half/
Reduce Array Size to The Half - LeetCode
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
내가 문제 해석을 잘 못했나.. 처음에는 좀 해맴.
결국 과반수 미만이 되는 최소 집합의 엘리먼트 수를 구하는게 목적이었음.
class Solution:
def minSetSize(self, arr: List[int]) -> int:
cnt = Counter(arr)
freq = sorted(cnt.values(), reverse=True)
mid = len(arr) // 2
ans = 0
while mid > 0:
mid -= freq[ans]
ans += 1
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.08.20 |
---|---|
Today's Challenge (0) | 2022.08.19 |
Today's Challenge (0) | 2022.08.17 |
Today's Challenge (0) | 2022.08.16 |
Today's Challenge (0) | 2022.08.15 |
Comments