Skip to content

Commit 404b1ba

Browse files
author
Daniel Nallapalli
committed
Solution #506 (Python) - Daniel - 16/06/2025 - commit #7
1 parent 76b0b15 commit 404b1ba

File tree

1 file changed

+20
-0
lines changed
  • Arrays & Strings/#506 - Relative Ranks - Easy

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution(object):
2+
def findRelativeRanks(self, score):
3+
"""
4+
:type score: List[int]
5+
:rtype: List[str]
6+
"""
7+
indexed_scores = sorted([(s, i) for i, s in enumerate(score)], reverse=True)
8+
9+
result = [''] * len(score)
10+
for rank, (s, i) in enumerate(indexed_scores):
11+
if rank == 0:
12+
result[i] = "Gold Medal"
13+
elif rank == 1:
14+
result[i] = "Silver Medal"
15+
elif rank == 2:
16+
result[i] = "Bronze Medal"
17+
else:
18+
result[i] = str(rank + 1)
19+
20+
return result

0 commit comments

Comments
 (0)