Leetcode Note: Go - Verifying an Alien Dictionary
Verifying an Alien Dictionary - LeetCode
https://leetcode.com/problems/verifying-an-alien-dictionary/
- Go 言語で取り組んだメモ
回答
Verifying an Alien Dictionary - LeetCode
https://leetcode.com/problems/verifying-an-alien-dictionary/solution/
Shortest golang solution - LeetCode Discuss
https://leetcode.com/problems/verifying-an-alien-dictionary/discuss/492642/Shortest-golang-solution
func isAlienSorted(words []string, order string) bool {
m := make(map[rune]rune)
for i, b := range order {
m[b] = rune('a' + byte(i))
}
for i, s := range words {
runes := []rune(s)
for i, r := range runes {
runes[i] = m[r]
}
words[i] = string(runes)
}
return sort.StringsAreSorted(words)
}