思路分析
没啥好说的,就是STL容器的使用吧。
AC代码
class Solution {
public:
char slowestKey(vector<int>& releaseTimes, string keysPressed) {
vector<int> v;
v.push_back(releaseTimes[0]);
for(int i = 1; i < releaseTimes.size(); i++)
v.push_back(releaseTimes[i] - releaseTimes[i - 1]);
int max = v[0];
char ans = keysPressed[0];
for(int i = 1; i < v.size(); i++) {
if(v[i] > max) {
max = v[i];
ans = keysPressed[i];
continue;
}
if(v[i] == max)
if(keysPressed[i] - ans > 0)
ans = keysPressed[i];
}
return ans;
}
};