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
- 코로나19
- github
- Docker
- Git
- 우분투
- leetcode
- PYTHON
- 편스토랑
- Kaggle
- Baekjoon
- 편스토랑 우승상품
- 더현대서울 맛집
- 맥북
- AI 경진대회
- 프로그래머스 파이썬
- 자연어처리
- 백준
- ChatGPT
- ubuntu
- 캐치카페
- Real or Not? NLP with Disaster Tweets
- programmers
- 데이콘
- hackerrank
- gs25
- SW Expert Academy
- dacon
- 프로그래머스
- 금융문자분석경진대회
- 파이썬
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
'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