Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 맥북
- gs25
- 금융문자분석경진대회
- 편스토랑
- 파이썬
- 데이콘
- 우분투
- PYTHON
- Docker
- 편스토랑 우승상품
- 코로나19
- 자연어처리
- 프로그래머스 파이썬
- ubuntu
- Kaggle
- 백준
- Real or Not? NLP with Disaster Tweets
- hackerrank
- 캐치카페
- 더현대서울 맛집
- dacon
- AI 경진대회
- Git
- leetcode
- programmers
- ChatGPT
- github
- 프로그래머스
- SW Expert Academy
- Baekjoon
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 506. Relative Ranks (Python) 본문
728x90
반응형

Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".
Example 1:
Input: [5, 4, 3, 2, 1]
Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]
Explanation: The first three athletes got the top three highest scores, so they got "Gold Medal", "Silver Medal" and "Bronze Medal".
For the left two athletes, you just need to output their relative ranks according to their scores.
Note:
- N is a positive integer and won't exceed 10,000.
- All the scores of athletes are guaranteed to be unique.
Solution
class Solution:
def findRelativeRanks(self, nums: List[int]) -> List[str]:
sorted_nums = sorted(nums, reverse=True)
answer = []
medal = ["Gold Medal", "Silver Medal", "Bronze Medal"]
rank_dict = {}
for i in range(len(sorted_nums)):
rank_dict[sorted_nums[i]] = i
for i in range(len(nums)):
if rank_dict[nums[i]] == 0:
answer.append("Gold Medal")
elif rank_dict[nums[i]] == 1:
answer.append("Silver Medal")
elif rank_dict[nums[i]] == 2:
answer.append("Bronze Medal")
else:
answer.append(str(rank_dict[nums[i]] + 1))
return answer



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
| [leetCode] 1337. The K Weakest Rows in a Matrix (Python) (0) | 2020.09.09 |
|---|---|
| [leetCode] 1331. Rank Transform of an Array (Python) (0) | 2020.09.08 |
| [leetCode] 1507. Reformat Date (Python) (0) | 2020.09.06 |
| [leetCode] 415. Add Strings (Python) (0) | 2020.09.05 |
| [leetCode] 917. Reverse Only Letters (Python) (0) | 2020.09.04 |
Comments