-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0621-TaskScheduler.cs
30 lines (26 loc) · 922 Bytes
/
0621-TaskScheduler.cs
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
//-----------------------------------------------------------------------------
// Runtime: 180ms
// Memory Usage: 34.9 MB
// Link: https://leetcode.com/submissions/detail/372798558/
//-----------------------------------------------------------------------------
using System;
namespace LeetCode
{
public class _0621_TaskScheduler
{
public int LeastInterval(char[] tasks, int n)
{
var count = new int[26];
foreach (var ch in tasks)
count[ch - 'A']++;
Array.Sort(count);
var max = count[25];
var left_count = max - 1;
var idleTime = left_count * (n + 1);
for (int i = 25; i >= 0 && count[i] > 0 && idleTime > 0; i--)
idleTime -= Math.Min(left_count, count[i]);
if (idleTime > 0) return idleTime + tasks.Length;
else return tasks.Length;
}
}
}