Skip to content

Commit c2c4658

Browse files
Sean PrashadSean Prashad
authored andcommitted
Update 621_Task_Scheduler.java
1 parent fcffe3f commit c2c4658

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

Greedy/621_Task_Scheduler.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public int leastInterval(char[] tasks, int n) {
3+
int result = 0;
4+
5+
int[] map = new int[26];
6+
for (char t : tasks) {
7+
if (t > 0) {
8+
map[t - 'A']++;
9+
}
10+
}
11+
12+
Arrays.sort(map);
13+
14+
while (map[25] > 0) {
15+
int iterations = 0;
16+
17+
while (iterations <= n) {
18+
if (map[25] == 0) {
19+
break;
20+
}
21+
22+
if (iterations < 26 && map[25 - iterations] > 0) {
23+
map[25 - iterations]--;
24+
}
25+
26+
++iterations;
27+
++result;
28+
}
29+
30+
Arrays.sort(map);
31+
}
32+
33+
return result;
34+
}
35+
}

Intervals/621_Task_Scheduler.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)