你的朋友正在使用键盘输入他的名字 name。偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次。 你将会检查键盘输入的字符 typed。如果它对应的可能是你的朋友的名字(其中

class Solution {
public:
bool isLongPressedName(string name, string typed) {
int num=name.size();
int i=0,j=0;
while(i<num)
{
if(name[i]==typed[j])
{
i++;
j++;
}
else
{
if(typed[j]==typed[j-1]&&j!=0)
{
j++;
}
else{
return false;
}
}
}
return true;
}
};

发布了81 篇原创文章 · 获赞 1 · 访问量 2774

猜你喜欢

转载自blog.csdn.net/weixin_44781382/article/details/104487205