Skip to content

Commit adfd95d

Browse files
committed
add
1 parent 9d9db1c commit adfd95d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

C++/task-scheduler.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Time: O(n)
2+
// Space: O(26) = O(1)
3+
4+
class Solution {
5+
public:
6+
int leastInterval(vector<char>& tasks, int n) {
7+
unordered_map<char,int> count;
8+
int max_count = 0;
9+
for (const auto& task : tasks) {
10+
++count[task];
11+
max_count = max(max_count, count[task]);
12+
}
13+
14+
auto result = (max_count - 1) * (n + 1);
15+
for (const auto& kvp : count) {
16+
if (kvp.second == max_count) {
17+
++result;
18+
}
19+
}
20+
return max(result, static_cast<int>(tasks.size()));
21+
}
22+
};

0 commit comments

Comments
 (0)