diff --git a/problems/0925.长按键入.md b/problems/0925.长按键入.md index 3502f2fb..70597508 100644 --- a/problems/0925.长按键入.md +++ b/problems/0925.长按键入.md @@ -134,7 +134,7 @@ Python: class Solution: def isLongPressedName(self, name: str, typed: str) -> bool: i, j = 0, 0 - m, n = len(name) , len(typed) + m, n = len(name) , len(typed) while i< m and j < n: if name[i] == typed[j]: # 相同时向后匹配 i += 1 @@ -155,8 +155,32 @@ class Solution: else: return False return True ``` + Go: +```go + +func isLongPressedName(name string, typed string) bool { + if(name[0] != typed[0] || len(name) > len(typed)) { + return false; + } + + idx := 0 // name的索引 + var last byte // 上个匹配字符 + for i := 0; i < len(typed); i++ { + if idx < len(name) && name[idx] == typed[i] { + last = name[idx] + idx++ + } else if last == typed[i] { + continue + } else { + return false + } + } + return idx == len(name) +} +``` + JavaScript: -----------------------