We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
秀哥好,925这道题,有个用例 输入name ="alex"typed ="aaleelx"预期结果false,参考网站解法时发现现在跑不通了。我的想法是在用双指针比较两个string时,如果typed对应元素与name对应元素不相等,多考虑一个if判断下当前typed元素是否和前一个typed元素相等,不相等直接返回false。 代码为: bool isLongPressedName(string name, string typed) { if(name.size()>typed.size()){ return false; } int len1=name.size(); int len2=typed.size(); unsigned i=0,j=0; while(i<len1 and j<len2){ if(name[i]==typed[j]){ i++; j++; } else{ // 如果当前字符与前一个字符相等,继续循环 if(j > 0 && typed[j] == typed[j - 1]){ j++; } // 否则,说明输入不符合要求,返回 false else{ return false; } } } while (j < len2 && typed[j] == typed[j - 1]) { j++; } return i == len1 && j == len2; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
秀哥好,925这道题,有个用例
输入name ="alex"typed ="aaleelx"预期结果false,参考网站解法时发现现在跑不通了。我的想法是在用双指针比较两个string时,如果typed对应元素与name对应元素不相等,多考虑一个if判断下当前typed元素是否和前一个typed元素相等,不相等直接返回false。
代码为:
bool isLongPressedName(string name, string typed) {
if(name.size()>typed.size()){
return false;
}
int len1=name.size();
int len2=typed.size();
unsigned i=0,j=0;
while(i<len1 and j<len2){
if(name[i]==typed[j]){
i++;
j++;
}
else{
// 如果当前字符与前一个字符相等,继续循环
if(j > 0 && typed[j] == typed[j - 1]){
j++;
}
// 否则,说明输入不符合要求,返回 false
else{
return false;
}
}
}
while (j < len2 && typed[j] == typed[j - 1]) {
j++;
}
return i == len1 && j == len2;
}
The text was updated successfully, but these errors were encountered: