mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2026-03-13 10:02:05 +08:00
Add solution 0791
This commit is contained in:
15
leetcode/0791.Custom-Sort-String/791. Custom Sort String.go
Normal file
15
leetcode/0791.Custom-Sort-String/791. Custom Sort String.go
Normal file
@@ -0,0 +1,15 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user