go: add «392. Is Subsequence»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
4bf8cc35ee
commit
0d1683fb1d
1 changed files with 18 additions and 0 deletions
18
go/is-subsequence.go
Normal file
18
go/is-subsequence.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
func isSubsequence(s string, t string) bool {
|
||||||
|
length := len(s)
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for j := range t {
|
||||||
|
if i < length && t[j] == s[i] {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
if i >= length {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return i == length
|
||||||
|
}
|
Loading…
Reference in a new issue