MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / IsSubsequence

Function IsSubsequence

strings/issubsequence.go:10–35  ·  view source on GitHub ↗

Returns true if s is subsequence of t, otherwise return false.

(s string, t string)

Source from the content-addressed store, hash-verified

8
9// Returns true if s is subsequence of t, otherwise return false.
10func IsSubsequence(s string, t string) bool {
11 if len(s) > len(t) {
12 return false
13 }
14
15 if s == t {
16 return true
17 }
18
19 if len(s) == 0 {
20 return true
21 }
22
23 sIndex := 0
24 for tIndex := 0; tIndex < len(t); tIndex++ {
25 if s[sIndex] == t[tIndex] {
26 sIndex++
27 }
28
29 if sIndex == len(s) {
30 return true
31 }
32 }
33
34 return false
35}

Callers 1

TestIsSubsequenceFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestIsSubsequenceFunction · 0.74