最近的请求次数
cpp
class RecentCounter {
public:
vector<int> arr;
RecentCounter() {
arr.push_back(0);
}
int ping(int t) {
arr.push_back(t);
while (arr[0] < t - 3000) {
arr.erase(arr.begin());
}
return arr.size() - (arr[0] == 0 ? 1 : 0);
}
};
Dota2 参议院
cpp
class Solution {
public:
string predictPartyVictory(string senate) {
queue<int> R, D;
for (int i = 0; i < senate.size(); i++) {
if (senate[i] == 'R') {
R.push(i);
} else {
D.push(i);
}
}
while (!R.empty() && !D.empty()) {
int r0 = R.front(), d0 = D.front();
if (r0 < d0) {
R.push(r0 + senate.size());
} else {
D.push(d0 + senate.size());
}
R.pop();
D.pop();
}
return D.empty() ? "Radiant" : "Dire";
}
};