![](https://img.haomeiwen.com/i328144/81da4840d4ae37a4.png)
![](https://img.haomeiwen.com/i328144/f7347a8bf40f9dd5.png)
思路: 就是利用双指针,因为typed
字符串长度一定 大于或者等于name
,条件才能成立
class Solution {
public boolean isLongPressedName(String name, String typed) {
int i = 0, j = 0;
while (j < typed.length()) {
if (i < name.length() && name.charAt(i) == typed.charAt(j)) {
i++;
j++;
} else if (j > 0 && typed.charAt(j) == typed.charAt(j-1) ) {
j++;
} else {
return false;
}
}
return i == name.length();
}
}
网友评论