Due to problem 925 test case change, so solution should modify

This commit is contained in:
YDZ
2020-09-09 20:51:49 +08:00
parent e02e370d4e
commit 0e424f7105
4 changed files with 41 additions and 30 deletions

View File

@ -7,20 +7,18 @@ func isLongPressedName(name string, typed string) bool {
if (len(name) == 0 && len(typed) != 0) || (len(name) != 0 && len(typed) == 0) {
return false
}
j := 0
for i := 0; i < len(name); i++ {
if j < len(typed) && name[i] == typed[j] {
i, j := 0, 0
for i < len(name) && j < len(typed) {
if name[i] != typed[j] {
return false
}
for i < len(name) && j < len(typed) && name[i] == typed[j] {
i++
j++
}
for j < len(typed) && typed[j] == typed[j-1] {
j++
continue
} else {
if i > 0 && j < len(typed) && name[i-1] == typed[j] {
j++
i--
} else {
return false
}
}
}
return true
return i == len(name) && j == len(typed)
}

View File

@ -32,6 +32,21 @@ func Test_Problem925(t *testing.T) {
ans925{true},
},
{
para925{"alex", "alexxr"},
ans925{false},
},
{
para925{"alex", "alexxxxr"},
ans925{false},
},
{
para925{"alex", "alexxxxx"},
ans925{true},
},
{
para925{"saeed", "ssaaedd"},
ans925{false},

View File

@ -53,8 +53,8 @@ Note:
## 解题思路
这一题也可以借助滑动窗口的思想。2 个字符串一起比较,如果遇到有相同的字符串,窗口继续往后滑动。直到遇到了第一个不同的字符,如果遇到两个字符串不相等的情况,可以直接返回 false。具体实现见代码。
- 这一题也可以借助滑动窗口的思想。2 个字符串一起比较,如果遇到有相同的字符串,窗口继续往后滑动。直到遇到了第一个不同的字符,如果遇到两个字符串不相等的情况,可以直接返回 false。具体实现见代码。
- 这一题的测试用例修改过一次,需要注意我这里写的第二组测试用例,当 name 结束以后,如果 typed 还有多余的不同的字符,这种情况要输出 false 的。具体见 test 文件里面的第二组,第三组,第四组测试用例。