Programming Language/Swift
[프로그래머스][Lv. 1] K번째 수 Swift 풀이
myungsup1250
2022. 3. 14. 15:37
https://programmers.co.kr/learn/courses/30/lessons/42748
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
풀이는 추후에 차차 올리도록 하겠습니다...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import Foundation
func solution(\_ array:\[Int\], \_ commands:\[\[Int\]\]) -> \[Int\] {
var ans = \[Int\]()
var temp = \[Int\]()
for command in commands {
temp = array
temp.removeLast(temp.count - command\[1\])
temp.removeFirst(command\[0\] - 1)
temp.sort()
ans.append(temp\[command\[2\] - 1\])
}
return ans
}
|
cs |