[프로그래머스] K번째 수 Swift

AekT·2021년 10월 23일
0

프로그래머스

목록 보기
2/6
post-thumbnail

프로그래머스 - K번째 수

문제 : https://programmers.co.kr/learn/courses/30/lessons/42748

자르고, 정렬하고, 배열에 추가하고, 리턴한다.

Swift :

import Foundation
func solution(_ array:[Int], _ commands:[[Int]]) -> [Int] {
    var arrays: [Int] = []
    for i in 0..<commands.count{
        var arr: [Int] = Array<Int>(array[commands[i][0]-1...commands[i][1]-1])
        arr.sort()
        arrays.append(arr[commands[i][2]-1])
    }
    return arrays
}

출처: 프로그래머스 코딩 테스트 연습, 정렬 - https://programmers.co.kr/learn/courses/30/lessons/42748

profile
으악

0개의 댓글