[python] 2751번 수 정렬하기2 (시간초과)

도리·2025년 2월 28일

내 코드

import sys
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()

for i in a:
    print(i)
  • 입력 : input()
  • list에 append
  • 정렬 : list.sort()
  • 출력 : for 문

정답 코드

import sys
n = int(input())
a = []
for _ in range(n):
    a.append(int(sys.stdin.readline()))
for i in sorted(a):
    print(i)

sort()

  • list.sort()
  • 기존 리스트 정렬

sorted()

  • sorted(list,tuple_이 경우 키값 정렬됨)
  • 새로운 정렬된 리스트를 만든다.
profile
인공지능응용학과 졸업

0개의 댓글