mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
925.长按键入 , 增加Golang实现
This commit is contained in:
@ -155,8 +155,32 @@ class Solution:
|
|||||||
else: return False
|
else: return False
|
||||||
return True
|
return True
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
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:
|
JavaScript:
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user