@@ -0,0 +1,1377 @@
+# Time:  O(n)%0A# Space: O(26) = O(1)%0A%0A# Given a char array representing tasks CPU need to do.%0A# It contains capital letters A to Z where different letters represent%0A# different tasks.Tasks could be done without original order.%0A# Each task could be done in one interval.%0A# For each interval, CPU could finish one task or just be idle.%0A#%0A# However, there is a non-negative cooling interval n that%0A# means between two same tasks, there must be at least n intervals that%0A# CPU are doing different tasks or just be idle.%0A#%0A# You need to return the least number of intervals the CPU%0A# will take to finish all the given tasks.%0A#%0A# Example 1:%0A# Input: tasks = %5B'A','A','A','B','B','B'%5D, n = 2%0A# Output: 8%0A# Explanation: A -%3E B -%3E idle -%3E A -%3E B -%3E idle -%3E A -%3E B.%0A# Note:%0A# The number of tasks is in the range %5B1, 10000%5D.%0A# The integer n is in the range %5B0, 100%5D.%0A%0Aclass Solution(object):%0A    def leastInterval(self, tasks, n):%0A        %22%22%22%0A        :type tasks: List%5Bstr%5D%0A        :type n: int%0A        :rtype: int%0A        %22%22%22%0A        count = collections.defaultdict(int)%0A        max_count = 0%0A        for task in tasks:%0A            count%5Btask%5D += 1%0A            max_count = max(max_count, count%5Btask%5D)%0A        %0A        result = (max_count-1) * (n+1)%0A        for count in count.values():%0A            if count == max_count:%0A                result += 1%0A        return max(result, len(tasks))%0A

Create task-scheduler.py