Problem Solving/LeetCode
Today's Challenge
fabichoi
2023. 1. 4. 23:45
https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/
Minimum Rounds to Complete All Tasks - LeetCode
Minimum Rounds to Complete All Tasks - You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level. Return the minimum rounds requ
leetcode.com
탐욕법으로 간단히 풀수 있음!
class Solution:
def minimumRounds(self, tasks: List[int]) -> int:
freqs = Counter(tasks)
res = 0
for freq in freqs.values():
if freq == 1:
return -1
res += ceil(freq/3)
return res
반응형