Skip to content

Commit 9182486

Browse files
committed
May 8
1 parent 9b89c56 commit 9182486

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

2024-05-May-LeetCoding-Challenge/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| May 5 | [237. Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/) | Medium | Solved |
1111
| May 6 | [2487. Remove Nodes From Linked List](https://leetcode.com/problems/remove-nodes-from-linked-list/) | Medium | Unsolved |
1212
| May 7 | []() | | |
13-
| May 8 | []() | | |
13+
| May 8 | [506. Relative Ranks](https://leetcode.com/problems/relative-ranks/) | Easy | Solved |
1414
| May 9 | []() | | |
1515
| May 10 | []() | | |
1616
| May 11 | []() | | |
@@ -39,6 +39,6 @@
3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
42-
| Easy | 2 | 2 | 0 |
42+
| Easy | 3 | 3 | 0 |
4343
| Medium | 4 | 3 | 1 |
4444
| Hard | 0 | 0 | 0 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def findRelativeRanks(self, score: List[int]) -> List[str]:
6+
elements = sorted([(s, i) for i, s in enumerate(score)])
7+
for medal in ('Gold Medal', 'Silver Medal', 'Bronze Medal'):
8+
if elements:
9+
score[elements[-1][1]] = medal
10+
elements.pop()
11+
for i, (_, idx) in enumerate(reversed(elements), start=4):
12+
score[idx] = str(i)
13+
return score
14+
15+
16+
def main():
17+
score = [5, 4, 3, 2, 1]
18+
assert Solution().findRelativeRanks(score) == ['Gold Medal',
19+
'Silver Medal',
20+
'Bronze Medal',
21+
'4',
22+
'5']
23+
24+
score = [10, 3, 8, 9, 4]
25+
assert Solution().findRelativeRanks(score) == ['Gold Medal',
26+
'5',
27+
'Bronze Medal',
28+
'Silver Medal',
29+
'4']
30+
31+
32+
if __name__ == '__main__':
33+
main()

0 commit comments

Comments
 (0)