2018-12-17 leetcode Task Scheduler Task Schedulercollections version - 84ms 123456789101112131415import collectionsclass Solution: def leastInterval(self, tasks, n): """ :type tasks: List[str] :type n: int :rtype: int """ d = collections.Counter(tasks) counts = d.values() longest = max(counts) ans = (longest - 1) * (n + 1) for cnt in counts: ans += cnt == longest and 1 or 0 return max(len(tasks), ans) test code 12In [98]: s = Solution(); t = s.leastInterval(["A","A","A","B","B","B"], 2); print(t)8 leet code Newer Best Time to Buy and Sell Stock with Cooldown Older Unique Binary Search Trees