-
[Programmers] 기능개발STUDYING/Algorithm 2021. 9. 27. 00:30728x90
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 }
'STUDYING > Algorithm' 카테고리의 다른 글
[Programmers] 멀쩡한 사각형 (0) 2021.09.27 [Programmers] 오픈채팅방 (0) 2021.09.27 [Programmers] 크레인 인형뽑기 (0) 2021.09.27 [BOJ] 11058 : 크리보드 (0) 2019.02.09 [BOJ] 1463 : 1로 만들기 (0) 2019.02.09