-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path506.py
executable file
·40 lines (33 loc) · 1.01 KB
/
506.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import copy
class Solution:
def findRelativeRanks(self, score: List[int]) -> List[str]:
# size == 1
if (len(score) == 1):
return ['Gold Medal']
# size == 2
if (len(score) == 2):
if (score[0] > score[1]):
return ['Gold Medal', 'Silver Medal']
return ['Silver Medal', 'Gold Medal']
# generate a sorted
val = copy.deepcopy(score)
val.sort()
val.reverse()
# print(val)
# map score to its sorted value index
v2i = {}
index = 0
for v in val:
if (index == 0):
v2i[v] = 'Gold Medal'
elif (index == 1):
v2i[v] = 'Silver Medal'
elif (index == 2):
v2i[v] = 'Bronze Medal'
else:
v2i[v] = str(index + 1)
index += 1
res = []
for sc in score:
res.append(v2i[sc])
return res