给定字符串 A 和 B ,输入 A 时某些字母会手抖打多遍,问 B 是否可能是 A 手抖后的结果。
思路:暴力即可,两个指针,满足不了条件就return false
class Solution {
public:
bool isLongPressedName(string name, string typed) {
int i=0,j=0;
int len1=name.length(),len2=typed.length();
if(len1>len2) return false;
while(i<len1||j<len2)
{
if(name[i]==typed[j]){
i++,j++;
}
else if(name[i-1]==typed[j])
{
j++;
}
else
{
return false;
}
}
return true;
}
};