Files
LeetCode-Go/leetcode/0791.Custom-Sort-String/791. Custom Sort String.go
2021-07-18 18:13:55 +08:00

16 lines
323 B
Go

package leetcode
import "sort"
func customSortString(order string, str string) string {
magic := map[byte]int{}
for i := range order {
magic[order[i]] = i - 30
}
byteSlice := []byte(str)
sort.Slice(byteSlice, func(i, j int) bool {
return magic[byteSlice[i]] < magic[byteSlice[j]]
})
return string(byteSlice)
}