Prepare > Python > Basic Data Types > Find the Runner-Up Score!
2024. 3. 21. 07:53ㆍHackerRank-Python
Find the Runner-Up Score! | HackerRank
For a given list of numbers, find the second largest number.
www.hackerrank.com
문제
Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given n scores. Store them in a list and find the score of the runner-up.
=> n개의 점수를 리스트에 저장하고 2등 점수를 찾아라
코드
if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
arr_set_li = list(set(list(arr)))
arr_set_li.sort()
print(arr_set_li[-2])
노트
print(
sorted(list(set(list(arr))))[-2]
)
- .sort(): 원본 정렬
- sorted(): 원본 유지, 정렬 리스트 리턴
'HackerRank-Python' 카테고리의 다른 글
itertools > Maximize It! (1) | 2024.02.12 |
---|---|
Prepare > Python > Python Functionals > Validating Email Addresses With a Filter (1) | 2023.10.04 |
Prepare > Python > Python Functionals > Reduce Function (0) | 2023.10.03 |
Prepare > Python > Built-Ins > ginortS (0) | 2023.10.02 |
Prepare > Python > Built-Ins > Athlete Sort (0) | 2023.10.01 |