티스토리 뷰
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42586
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
풀이
- 각 프로세스별 걸리는 날짜를 계산
- 이전 프로세스가 현재 프로세스보다 오래 걸리면 날짜를 이전 프로세스로 변경
- 같은 프로세스 시간의 개수를 구해서 출력
전체코드
import Foundation
func solution(_ progresses:[Int], _ speeds:[Int]) -> [Int] {
var result: [Int] = []
var times: [Int] = zip(progresses, speeds).map{
if (100-$0.0) % $0.1 == 0 { return (100-$0.0) / $0.1 }
return (100-$0.0) / $0.1 + 1
}
for idx in 1..<times.count {
if times[idx] < times[idx-1] {
times[idx] = times[idx-1]
}
}
var day: Int = times[0]
var total: Int = 0
for time in times {
if day == time {
total += 1
} else{
result.append(total)
total = 1
day = time
}
}
result.append(total)
return result
}
'PS > 문제 풀이' 카테고리의 다른 글
| [프로그래머스/Swift] 64065번 - 튜플 (0) | 2025.02.01 |
|---|---|
| [프로그래머스/Swift] 87946번 - 피로도 (1) | 2025.01.30 |
| [프로그래머스/Swift] 17680번 - [1차] 캐시 (1) | 2025.01.28 |
| [프로그래머스/Swift] 42747번 - H-Index (0) | 2025.01.28 |
| [프로그래머스/Swift] 42578번 - 의상 (0) | 2025.01.26 |
