Untitled
unknown
c_cpp
2 years ago
903 B
11
Indexable
class Comp{
public:
bool operator()(pair<int,int> &a , pair<int,int> &b){
return a.first > b.first;
}
};
class Solution {
public:
int leastInterval(vector<char>& arr, int t) {
priority_queue<pair<int,int>,vector<pair<int,int>> , Comp> 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==0 || p.second < tt){
q.pop();
cout<<p.first<<" "<<p.second<<" "<<p.first-1<<" "<<p.second+1<<endl;
if(p.first>1) q.push({p.first - 1 , p.second + t});
}
tt++;
}
return tt;
}
};Editor is loading...
Leave a Comment