mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
925.长按键入 , 增加Golang实现
This commit is contained in:
@ -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:
|
||||
|
||||
-----------------------
|
||||
|
Reference in New Issue
Block a user