Skip to content

Instantly share code, notes, and snippets.

@florinutz
Created November 7, 2019 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florinutz/bf915aa42d4d728d356fb0e016d40a4f to your computer and use it in GitHub Desktop.
Save florinutz/bf915aa42d4d728d356fb0e016d40a4f to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
fmt.Printf("%v\n", find("apple", "ale")) // true
fmt.Printf("%v\n", find("apple", "alp")) // false
}
func find(haystack, needle string) bool {
if len(needle) == 0 {
return true
}
for i, c := range haystack {
if c == int32(needle[0]) {
return find(haystack[i:], needle[1:])
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment