File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 134
134
| 500 | [ Keyboard Row] ( https://leetcode.com/problems/keyboard-row ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/KeyBoardRow.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/keyboard_row.py ) |
135
135
| 501 | [ Find Mode in Binary Search Tree] ( https://leetcode.com/problems/find-mode-in-binary-search-tree ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/FindModeInBinarySearchTree.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/find_mode_in_binary_search_tree.py ) |
136
136
| 504 | [ Base 7] ( https://leetcode.com/problems/base-7 ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/Base7.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/base_7.py ) |
137
- | 506 | [ Relative Ranks] ( https://leetcode.com/problems/relative-ranks ) | Easy | |
137
+ | 506 | [ Relative Ranks] ( https://leetcode.com/problems/relative-ranks ) | Easy | [ ![ Python ] ( https://img.icons8.com/color/35/000000/python.png )] ( python/relative_ranks.py ) |
138
138
| 507 | [ Perfect Number] ( https://leetcode.com/problems/perfect-number ) | Easy | |
139
139
| 509 | [ Fibonacci Number] ( https://leetcode.com/problems/fibonacci-number ) | Easy | |
140
140
| 520 | [ Detect Capital] ( https://leetcode.com/problems/detect-capital ) | Easy | |
Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
3
+
4
+ class Solution :
5
+ def get_rank (self , position : int ) -> str :
6
+ if position == 1 : return 'Gold Medal'
7
+ if position == 2 : return 'Silver Medal'
8
+ if position == 3 : return 'Bronze Medal'
9
+ return str (position )
10
+
11
+ def findRelativeRanks (self , score : List [int ]) -> List [str ]:
12
+ numbers = [(index , val ) for index , val in enumerate (score )]
13
+ numbers .sort (key = lambda x : x [1 ], reverse = True )
14
+ value_to_index = {}
15
+ for index , (_ , value ) in enumerate (numbers ):
16
+ value_to_index [value ] = index
17
+ result = ['' ] * len (score )
18
+ for index , value in enumerate (score ):
19
+ result [index ] = self .get_rank (value_to_index [value ] + 1 )
20
+ return result
You can’t perform that action at this time.
0 commit comments