티스토리 뷰
1. 문제
https://programmers.co.kr/learn/courses/30/lessons/42586
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
2. 설명
완성되는데 필요한 날을 구하고, 그 전 기능이 완료가 안되면 days를 증가시켰다.
스택, 큐 안쓰고 배열만으로 했다.
★ Integer List --> int[] array : list.stream().mapToInt(Integer::intValue).toArray();
3. 코드
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
int[] answer;
ArrayList<Integer> list = new ArrayList<>();
int[] publish = new int[progresses.length];
for(int i=0; i<progresses.length; i++) {
int n = 0;
while(progresses[i]<100) {
progresses[i] += speeds[i];
n += 1; // 하루 증가
}
publish[i] = n;
}
for(int i=0; i<publish.length-1; i++) {
if(publish[i] > publish[i+1])
publish[i+1] = publish[i];
}
int days = 1;
for(int i=0; i<publish.length-1; i++) {
if(publish[i]==publish[i+1])
days +=1;
else {
list.add(days);
days = 1;
}
}
list.add(days);
answer = list.stream().mapToInt(Integer::intValue).toArray();
return answer;
}
}
'알고리즘 풀이 > 프로그래머스' 카테고리의 다른 글
프로그래머스 124 나라의 숫자 JAVA (0) | 2020.05.18 |
---|---|
프로그래머스 탑 JAVA (0) | 2020.05.13 |
프로그래머스 주식가격 JAVA (0) | 2020.05.12 |
프로그래머스 [3차] 방금그곡 JAVA (0) | 2020.05.08 |
프로그래머스 문자열 단축 JAVA (0) | 2020.05.06 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday