티스토리 뷰

문제

https://school.programmers.co.kr/learn/courses/30/lessons/42586

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

풀이

  1. 각 프로세스별 걸리는 날짜를 계산
  2. 이전 프로세스가 현재 프로세스보다 오래 걸리면 날짜를 이전 프로세스로 변경
  3. 같은 프로세스 시간의 개수를 구해서 출력

전체코드

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
}

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함