Created
November 7, 2019 11:02
-
-
Save florinutz/bf915aa42d4d728d356fb0e016d40a4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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