Untitled
unknown
c_cpp
2 years ago
665 B
12
Indexable
class Solution {
public:
int leastInterval(vector<char>& arr, int t) {
priority_queue<pair<int,int>> q; // count , letter
vector<int>v(26,0);
int res = 0;
int n = arr.size();
for(auto i : arr)
v[i-'A']++;
for(int i = 0; i<26; i++)
if(v[i]){
q.push(make_pair(v[i],0));
}
int tt = 0;
while(q.size()){
pair<int,int> p = q.top();
if(p.second<=tt){
q.pop();
if(p.first>1) q.push({p.first-1 , tt+t});
}
tt++;
res++;
}
return res;
}
};Editor is loading...
Leave a Comment