상세 컨텐츠

본문 제목

[프로그래머스] 기능 개발

💯ProblemSolving/문제 풀이-Java

by :부셔져버린개발자 2024. 12. 16. 12:28

본문

       문제 요약        

- 문제

앞에 있는 기능이 먼저 배포되어야 한다.

즉, 앞에 있는 기능을 완료하는데 5일이 걸리고, 뒤 기능을 완료하는데 2일이 걸린다면

5일 동안 배포되지 못하다가 앞에 기능이 완료 되는 즉시 뒤 기능도 이미 완료 되었으므로 배포 가능하다 

 

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

 

프로그래머스

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

programmers.co.kr

 

         아이디어        

 

작업은 동시에 시작된다 

배포가 Block 될 뿐..!

 

따라서, 아래와 같은 예시를 생각해야 한다.

[85, 80, 90, 85] [5, 5, 5, 5]  [1, 3]

         소스코드        

 

import java.util.*;
class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
        List<Integer> ans = new ArrayList<>();
        for(int i = 0; i < progresses.length; i++) {
            progresses[i] = (int)Math.ceil((double)(100 - progresses[i])/speeds[i]);
        }
        
        int cnt = 0;
        int prev = progresses[0];
        for(int i = 0; i < progresses.length; i++) {
            if(prev >= progresses[i]) {
                cnt += 1;
            } else {
                ans.add(cnt);
                cnt = 1;
            }
           prev = Math.max(prev,progresses[i]);
        }
        if(cnt > 0) {
            ans.add(cnt);
        }
        return ans.stream().mapToInt(Integer::intValue).toArray();
    }
}

 

728x90

관련글 더보기