반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- @configuration
- 루씬 인 액션
- 쿠버네티스
- 크론 표현식
- 커링
- @Setter
- Java
- 완주하지 못한 선수
- 검색 기능 확장
- 스택/큐
- H-index
- 가장 큰 수
- 기능개발
- 모던 자바 인 액션
- 프로그래머스
- @Getter
- @Data
- 정렬
- 다리를 지나는 트럭
- 롬복 어노테이션
- 스프링 스케쥴러
- K번째수
- @EnableScheduling
- 알고리즘
- kubenetes
- 고차원 함수
- 영속 자료구조
- 해시
- 코딩 테스트
- 전화번호 목록
Archives
- Today
- Total
Today I Learned
[프로그래머스] 스택/큐 Level 2. 기능개발(JAVA) 본문
728x90
개발기간은 Math.ceil 함수로 올림하여 계산
다음 배포일 이내 개발건들을 카운트하여 배포목록에 추가
코드
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
ArrayList<Integer> deployList = new ArrayList<Integer>();
int deployCnt = 0;
int nextDeploy = 0;
for(int i = 0; i < progresses.length; i++){
int period = (int)Math.ceil((100-progresses[i]) / (double)speeds[i]);
System.out.println(period);
if(nextDeploy == 0){ //최초 배포일
deployCnt = 1;
nextDeploy = period;
continue;
}
if(nextDeploy < period){ //다음 배포일로 넘김
nextDeploy = period;
deployList.add(deployCnt);
deployCnt = 1; //배포건 수 초기화
}else{ //기존 배포건 수에 추가
deployCnt++;
}
}
deployList.add(deployCnt);//마지막 배포일 추가
int[] answer = new int[deployList.size()];
for(int i = 0; i < deployList.size(); i++){
answer[i] = deployList.get(i);
}
return answer;
}
}
결과
점수는 6점
다른 풀이는 생략
728x90
'알고리즘 & 코딩테스트' 카테고리의 다른 글
[프로그래머스] 스택/큐 Level 2. 다리를 지나는 트럭(JAVA) (0) | 2021.02.03 |
---|---|
[프로그래머스] 스택/큐Level 2. 주식가격(JAVA) (0) | 2021.01.28 |
[프로그래머스] 정렬 Level 2. H-Index(JAVA) (0) | 2021.01.27 |
[프로그래머스] 정렬 Level 2. 가장 큰 수(JAVA) (0) | 2021.01.24 |
[프로그래머스] 정렬 Level 1. K번째수(JAVA) (0) | 2021.01.22 |
Comments