https://school.programmers.co.kr/learn/courses/30/lessons/42586
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
코드
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
/*
1. 각 작업별 소요 시간을 구해 배열로 담는다.
a. 소요시간 : count =(100 - progresses[i])/speed[i];
(100 - progresses[i])%speed[i]>0 ? count++: ;
b. 배열에 담기
int[] days = new int[progresses.length];
for(int i=0; i<progresses.length; i++){
count =(100 - progresses[i])/speed[i];
(100 - progresses[i])%speed[i]>0 ? count++: ;
days[i]=count
}
2. 작업 소요시간 배열의 요소를 처음부터 순회하며
a. 자신보다 큰 값이 나오면 그때의 배열 인덱스 값을 answer에 넣는다.
b. 배열의 끝에 다다르면 그때의 배열 인덱스 +1 값을 answer에 넣는다.
*/
ArrayList<Integer> list = new ArrayList<>();
int count = 0;
int[] days = new int[progresses.length];
for(int i=0; i<progresses.length; i++){
count =(100 - progresses[i])/speeds[i];
if((100 - progresses[i])%speeds[i]>0){
count++;
}
days[i]=count;
}
int max = days[0];
int tmp = 0;
for(int i=1; i<days.length; i++){
tmp++;
if(max<days[i]){
max=days[i];
list.add(tmp);
tmp=0;
}
}
list.add(++tmp);
int[] arr = list.stream()
.mapToInt(Integer::intValue)
.toArray();
return arr;
}
}
뭔가 오랜만에 오롯이 나의 힘으로 풀어낸 것 같다..(ㅠ)
시간은 35분정도 소요되었다.
'알고리즘 > 문제' 카테고리의 다른 글
| *[프로그래머스] Lv2 k진수에서 소수 개수 구하기 / Java (0) | 2023.03.27 |
|---|---|
| [프로그래머스] Lv2 타겟 넘버 / JAVA (0) | 2023.03.24 |
| *[프로그래머스] Lv2 N^2 배열자르기 / JAVA (0) | 2023.03.21 |
| *[프로그래머스] Lv2 리코쳇 로봇 / JAVA (0) | 2023.03.20 |
| *[프로그래머스] Lv2 이모티콘 할인행사 / JAVA (0) | 2023.03.17 |
