2244. Minimum Rounds to Complete All Tasks

2022. 5. 1. 14:55Algorithm/Leetcode, Lintcode, HackerRank, etc.

    목차
반응형

 

 

class Solution:
    def minimumRounds(self, tasks: List[int]) -> int:
        freq = collections.Counter(tasks)
        cnt = 0
        
        for num, count in freq.items():
            if count < 2:
                return -1
            
            while count >= 2:
                if (count > 2 and count % 2 != 0) or count % 3 == 0:
                    count -= 3
                else:
                    count -= 2
                
                cnt += 1

        return cnt
반응형