Is Subsequence using Golang

 Is Sub sequence : we solved this question from leetcode, in this problem we have given two input string where we need  find that first string is Sub-sequence of second string.

Subsequence


Solution:

func isSubsequence(s string, t string) bool {
source := []rune(t)
dest := []rune(s)
gotIndex := 0
for i := 0; i < len(dest); i++ {
var found bool
for j := gotIndex; j < len(source); j++ {
if source[j] == dest[i] {
gotIndex = j + 1
found = true
break
}
}
if !found {
return found
}
}
return true
}


Post a Comment

0 Comments