Skip to content

Instantly share code, notes, and snippets.

@ameliagapin
Created July 10, 2017 13:36
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 ameliagapin/59631e6b3acd8037a8aa1738b9214dc5 to your computer and use it in GitHub Desktop.
Save ameliagapin/59631e6b3acd8037a8aa1738b9214dc5 to your computer and use it in GitHub Desktop.
LIVE phone screen
package main
import (
"fmt"
"strings"
)
func main() {
result := search("apple.go", "ago")
stringResult := "false"
if result {
stringResult = "true"
}
fmt.Println("Result: " + stringResult)
}
func search(filename string, pattern string) bool {
fileSlice := strings.Split(filename, "")
patternSlice := strings.Split(pattern, "")
lastCharFound := 0
for _, patternChar := range patternSlice {
found := false
for i := lastCharFound; i < len(fileSlice); i++ {
if patternChar == fileSlice[i] {
found = true
lastCharFound = i + 1
break
}
}
if found {
continue
}
return false
}
return true
}
package main
import (
"fmt"
)
func main() {
listA := []string{
"a",
"b",
"c",
}
listB := []string{
"b",
"c",
"d",
}
hashmap := make(map[string]bool)
for _, value := range listB {
hashmap[value] = true
}
for _, search := range listA {
if _, ok := hashmap[search]; ok {
fmt.Println(search)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment