leetcode-925-easy
Long Pressed Name
思路一: 暴力,遍历两个字符串,对比。边界情况不太好处理
public boolean isLongPressedName(String name, String typed) {
if (typed.length() < name.length()) return false;
int left = 0;
int right = 0;
while (left < name.length() && right < typed.length()) {
char t1 = name.charAt(left);
int count = 0;
while (left < name.length() && name.charAt(left) == t1) {
left++;
count++;
}
char t2 = typed.charAt(right);
int count2 = 0;
while (right < typed.length() && typed.charAt(right) == t2) {
right++;
count2++;
}
if (t1 != t2 || count > count2) {
return false;
}
}
return left == name.length() && right == typed.length();
}

浙公网安备 33010602011771号