| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 월간
- 10분
- 운동
- realclass
- 영어원서읽기
- English
- 읽기
- 사이드
- 30분
- 미드시청
- FIT XR
- 개발자
- Daily Challenge
- 화상영어
- 쓰릴오브파이트
- 영어공부
- Writing
- 프로젝트
- 링피트
- 만화도
- 리얼 클래스
- 파비최
- leetcode
- Problem Solving
- 매일
- 3줄정리
- 잡생각
- 뭐든
- 괜찮음
- 스탭퍼
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.11.21 Today's Challenge 본문
Frequency of the Most Frequent Element - LeetCode
Can you solve this real interview question? Frequency of the Most Frequent Element - The frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you can choose an index o
leetcode.com
문제를 딱 봤을 때 슬라이딩 윈도우로 푸는거 같았는데, 역시나.
class Solution:
def maxFrequency(self, nums: List[int], k: int) -> int:
nums.sort()
left, ans, curr = 0, 0, 0
for right in range(len(nums)):
target = nums[right]
curr += target
while (right - left + 1) * target - curr > k:
curr -= nums[left]
left += 1
ans = max(ans, right - left + 1)
return ans반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.11.23 Today's Challenge (1) | 2023.11.23 |
|---|---|
| 2023.11.22 Today's Challenge (0) | 2023.11.22 |
| 2023.11.20 Today's Challenge (1) | 2023.11.20 |
| 2023.11.19 Today's Challenge (0) | 2023.11.19 |
| 2023.11.18 Today's Challenge (0) | 2023.11.18 |
Comments