题目
不想多说
代码语言:javascript复制class TweetCounts {
public:
map<string,multiset<int>> m;
TweetCounts() {
m.clear();
}
void recordTweet(string tweetName, int time) {
m[tweetName].insert(time);
}
vector<int> getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {
int inter = freq=="minute"?60:(freq=="hour"?60*60:60*60*24);
vector<int> ans;
for(int i=0;i<(endTime-startTime)/inter 1;i )
{
ans.push_back(0);
}
for(multiset<int>::iterator iter=m[tweetName].begin();iter!=m[tweetName].end(); iter)
{
if(*iter>endTime)
break;
if(*iter>=startTime){
int x = (*iter - startTime)/inter;
ans[x] ;
}
}
return ans;
}
};
/**
* Your TweetCounts object will be instantiated and called as such:
* TweetCounts* obj = new TweetCounts();
* obj->recordTweet(tweetName,time);
* vector<int> param_2 = obj->getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);
*/