MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / isAlienSorted

Function isAlienSorted

verifying_an_alien_dictionary_953/solution.go:3–16  ·  view source on GitHub ↗
(words []string, order string)

Source from the content-addressed store, hash-verified

1package verifying_an_alien_dictionary_953
2
3func isAlienSorted(words []string, order string) bool {
4 charToIndex := make(map[string]int)
5 for idx, ch := range order {
6 charToIndex[string(ch)] = idx
7 }
8
9 for i := 0; i < len(words)-1; i++ {
10 if compareAlienStrings(words[i], words[i+1], charToIndex) == 1 {
11 return false
12 }
13 }
14
15 return true
16}
17
18// Returns -1 if s1 < s2, 0 if s1 == s2, and 1 if s1 > s2
19func compareAlienStrings(s1, s2 string, charToIndex map[string]int) int {

Callers 1

Test_isAlienSortedFunction · 0.85

Calls 1

compareAlienStringsFunction · 0.85

Tested by 1

Test_isAlienSortedFunction · 0.68