Returns true if s is subsequence of t, otherwise return false.
(s string, t string)
| 8 | |
| 9 | // Returns true if s is subsequence of t, otherwise return false. |
| 10 | func 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 | } |
no outgoing calls