Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Created January 16, 2020 06:08
Show Gist options
  • Select an option

  • Save dalcon10028/21e0874deb569cd44085f1461fa7aa07 to your computer and use it in GitHub Desktop.

Select an option

Save dalcon10028/21e0874deb569cd44085f1461fa7aa07 to your computer and use it in GitHub Desktop.
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
ArrayList<Integer> period = new ArrayList<>(); // 각 작업마다 걸리는 기간
ArrayList<Integer> result = new ArrayList<>(); // 결과 값
for(int i=0; i<speeds.length; i++){
double restProgress = 100-progresses[i];
period.add((int)(Math.ceil(restProgress/speeds[i]))); //각 작업에 대한 배포가능한 날짜
// [7, 3, 9]
}
int criteria = period.get(0); // 첫 번째 작업을 기준으로 저장
int count = 1;
for(int i=1; i<speeds.length;i++){ // 기준에 대해 비교를 합니다.
if (criteria < period.get(i) ) { // 기준값보다 이후 값이 더 크면
result.add(count); // 결과값에다 넣어주고
count=1; // 기능 수를 초기화 시켜주고
criteria = period.get(i); // 기준값을 바꾸어 줍니다.
} else { // 아닐경우
count++; // 배포되는 기능수를 1더해줍니다.
}
}
result.add(count);
// 답안 제출을 위한 변환과정
int []answer = new int[result.size()];
for(int i=0; i<answer.length; i++)
answer[i] = result.get(i);
return answer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment