Created
July 10, 2017 13:36
-
-
Save ameliagapin/59631e6b3acd8037a8aa1738b9214dc5 to your computer and use it in GitHub Desktop.
LIVE phone screen
This file contains 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" | |
"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 | |
} |
This file contains 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() { | |
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