https://programmers.co.kr/learn/courses/30/lessons/42586
코딩테스트 연습 - 기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는
programmers.co.kr
스택을 사용한 문제
포인트는
입력받은 progresses를 stack에 거꾸로 넣어줘야한다.
peak가 앞에 문제가 되도록
풀이
import java.util.*;
public class Solution {
public int[] solution(int[] progresses, int[] speeds) {
ArrayList<Integer> answerTemp = new ArrayList<>();
Stack<Integer> progress = new Stack<>();
Stack<Integer> speed = new Stack<>();
for(int i = progresses.length-1; i>=0 ; i--){
progress.push(progresses[i]);
speed.push(speeds[i]);
}
while(!progress.isEmpty()){
int cnt = 0;
if(progress.peek() == 100){
progress.pop();
speed.pop();
cnt++;
while (!progress.isEmpty() && progress.peek() == 100) {
progress.pop();
speed.pop();
cnt++;
}
}else{
// 진도율 올려준
for(int i=0; i<progress.size(); i++){
progress.set(i, Math.min(100, progress.get(i) + speed.get(i)));
}
}
if(cnt > 0){
answerTemp.add(cnt);
}
}
int[] answer = new int[answerTemp.size()];
for(int i = 0; i< answerTemp.size(); i++){
answer[i] = answerTemp.get(i);
}
return answer;
}
}'PROGRAMMING > ALGORITHM' 카테고리의 다른 글
| [백준] 2193번 이친수 JAVA DP (0) | 2021.06.10 |
|---|---|
| [백준] 10844번 쉬운 계단 수 JAVA DP (0) | 2021.05.30 |
| [프로그래머스] 모의고사 JAVA (0) | 2021.05.23 |
| [프로그래머스] 체육복 JAVA (0) | 2021.05.22 |
| [프로그래머스] K번째수 JAVA (0) | 2021.05.20 |