class Solution {
public:
int calculateTime(string keyboard, string word) {
int now,last=0,sum = 0;
for(int i = 0; i < word.size(); i++){
for(int j = 0; j < keyboard.size();j++){
if(word[i] == keyboard[j]){
now = j;
break;
}
}
sum = sum + (now -last >= 0 ? now - last : last - now);
last = now;
}
return sum;
}
};
leetcode7.7单行键盘
最新推荐文章于 2022-01-02 05:38:44 发布