[백준] 11652번 카드

거북이·2023년 1월 12일
0

백준[실버4]

목록 보기
33/91
post-thumbnail

💡문제접근

  • list를 이용한 방법보다는 딕셔너리를 이용한 방법이 더 좋을 것 같아 딕셔너리를 사용했다.
  • Python으로 제출했더니 시간초과가 발생해 PyPy3로 제출했더니 정상적으로 출력되었다.

💡코드(메모리 : 128704KB, 시간 : 216ms, PyPy3로 제출)

import sys

N = int(input())

dict = {}
for _ in range(N):
    value = int(sys.stdin.readline().strip())
    if value not in dict:
        dict[value] = 1
    else:
        dict[value] += 1

new_dict = sorted(dict.items(), key = lambda x : (-x[1], x[0]))
print(new_dict[0][0])

💡소요시간 : 1m

0개의 댓글