Prepare > Python > Basic Data Types > Find the Runner-Up Score!

2024. 3. 21. 07:53HackerRank-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(): 원본 유지, 정렬 리스트 리턴