(words []string, order string)
| 1 | package verifying_an_alien_dictionary_953 |
| 2 | |
| 3 | func 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 |
| 19 | func compareAlienStrings(s1, s2 string, charToIndex map[string]int) int { |