1.题目:​​https://leetcode-cn.com/problems/long-pressed-name/​

2.思路

(1)i,j分别指向name和typed,遍历时如果name[i]==typed[j] 则i++,j++;否则判断typed[j]==typed[j-1] 如果为假则返回false,否则 为true;

3.代码

https://leetcode-cn.com/problems/long-pressed-name/solution/cshi-xian-zui-you-jie-shuang-zhi-zhen-by-yang-zi-j/
class Solution {
public:
bool isLongPressedName(string name, string typed) {
int i=0,j=0;
if (name[i]!=typed[j])
return false;

while (i<name.length())// while (i<name.length() && j<typed.length()),这样写不能保证某些用例通过,很简单自己去分析
{
if (name[i]==typed[j])
{
i++,j++;
}
else
{
if (typed[j]!=typed[j-1])
return false;
else
j++;
}
}
return true;
}
};