add: leetcode 0506 solution

This commit is contained in:
tphyhFighting
2021-12-02 09:58:05 +08:00
parent a45992e7de
commit 257b503f8a

View File

@ -0,0 +1,29 @@
package leetcode
import (
"sort"
"strconv"
)
func findRelativeRanks(score []int) []string {
mp := make(map[int]int)
for i, v := range score {
mp[v] = i
}
sort.Slice(score, func(i, j int) bool {
return score[i] > score[j]
})
ans := make([]string, len(score))
for i, v := range score {
if i == 0 {
ans[mp[v]] = "Gold Medal"
} else if i == 1 {
ans[mp[v]] = "Silver Medal"
} else if i == 2 {
ans[mp[v]] = "Bronze Medal"
} else {
ans[mp[v]] = strconv.Itoa(i + 1)
}
}
return ans
}