알고리즘 풀이/프로그래머스

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

배게 2019. 3. 15. 00:33
728x90

1일씩 지날 때마다 속도량(speeds)만큼 작업의 양(progresses)를 늘려줌


index는 0부터 시작하고 작업량이 100이상인지 하루가 지날때마다 체크해줌


현재 index가 100이상일 경우 배포시작임 배포시작부터 index를 늘려주면서


미완료될때까지 complete와 index를 늘려줌


 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
32
33
34
35
import java.util.*;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) {

        List<Integer> ans = new ArrayList<Integer>();

        int index=0;
        int n=progresses.length;


        while(index<n){
            int complete=0;

            for(int j=0; j<n; j++){
                progresses[j] += speeds[j];
            }
            while(index<n){
                if(progresses[index]>=100) {
                    complete++;
                    index++;
                }
                else break;
            }
            if(complete>0) ans.add(complete);
        }

        int[] answer = new int[ans.size()];
        for(int i=0; i<ans.size(); i++){
            answer[i] = ans.get(i);
        }

        return answer;
    }
}