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