[프로그래머스] 1단계_k번째수 (python)

juyeon·2022년 6월 14일
0

코딩테스트(python)

목록 보기
8/22

프로그래머스

1단계_k번째수

나의 풀이

def solution(array, commands):
    return [sorted(array[i-1:j])[k-1] for i, j, k in commands]

: list.sort() vs sorted(list) 의 차이점을 알자!

  • list.sort(): 원본을 변경.
  • sorted(list): 별도본.

sort로 했다가 오류나서.. 구글링 해서 sorted로 바꿨더니, 성공!

다른 사람 풀이(프로그래머스)

def solution(array, commands):
    return list(map(lambda x:sorted(array[x[0]-1:x[1]])[x[2]-1], commands))

: 람다 사용.

map 함수

: https://velog.io/@juyeonma9/조각-문법-for-python

profile
내 인생의 주연

0개의 댓글