STUDYING/Algorithm
[Programmers] 기능개발
EOZIN
2021. 9. 27. 00:30
728x90
https://programmers.co.kr/learn/courses/30/lessons/42586
import Foundation
func solution(_ progresses:[Int], _ speeds:[Int]) -> [Int] {
// 작업 개수
let workCnt = progresses.count
let remainProgress = progresses.compactMap{ 100 - $0 }
var workQ: [Int] = []
var resultArr: [Int] = []
for i in 0..<workCnt {
if remainProgress[i]%speeds[i] != 0 {
workQ.append(remainProgress[i]/speeds[i] + 1)
} else {
workQ.append(remainProgress[i]/speeds[i])
}
}
print("workq : ", workQ)
var workFirst = workQ.first ?? 0
workQ.removeFirst()
var cnt = 1
while !workQ.isEmpty {
let newWorkFirst = workQ.first ?? 0
if workFirst < newWorkFirst {
workFirst = newWorkFirst
resultArr.append(cnt)
cnt = 1
} else {
cnt += 1
}
workQ.removeFirst()
if workQ.count == 0 {
resultArr.append(cnt)
break
}
}
return resultArr
}