티스토리 뷰
https://programmers.co.kr/learn/courses/30/lessons/42586
코딩테스트 연습 - 기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 ��
programmers.co.kr
풀이법:
1) (100 - progresses) ÷ speeds 를 계산한 days 라는 배열을 만든다.
2) 이 배열을 순차적으로 탐색하면서 누적된 일수를 계산한다.
(주식가격 문제랑 거의 똑같은 느낌.. 주식가격 문제: https://argonautsfleece.tistory.com/13)
Comment:
1) 이건 스택/큐 문제라기 보다 배열 능숙하게 다룰 수 있는 지 물어보는 문제인거 같은데?
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
int days[] = new int[progresses.length];
for(int i = 0; i < progresses.length; i++) {
if((100 - progresses[i]) % speeds[i] == 0)
days[i] = (100 - progresses[i]) / speeds[i];
else
days[i] = ((100 - progresses[i]) / speeds[i]) + 1;
System.out.println(days[i]);
}
ArrayList<Integer> ans = new ArrayList();
int j = 0;
for(int i = 0; i < days.length; i++) {
int count = 0;
for(j = i + 1; j < days.length; j++) {
if(days[i] < days[j]) {
i = j - 1;
break;
}
count++;
}
ans.add(count + 1);
if(j == days.length) break;
}
int[] answer = new int[ans.size()];
for(int i = 0; i < answer.length;i++){
answer[i] = ans.get(i);
}
return answer;
}
}
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 힙 : 더 맵게 (0) | 2020.09.05 |
---|---|
[프로그래머스] 스택/큐 : 프린터 (0) | 2020.08.07 |
[프로그래머스] 스택/큐 : 주식가격 (0) | 2020.08.05 |
[프로그래머스] 해시 : 베스트앨범 (0) | 2020.08.05 |
[프로그래머스] 해시 : 위장 (0) | 2020.08.04 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 카카오 인턴
- 프로그래밍 모델
- 2020 KAKAO
- IOC
- PatternSyntaxException
- zipkin
- nginx 내부
- KAKAO 2021
- Java
- WORA
- Kakao Blind
- decorator
- 카카오코테
- 카카오
- Java #GC #가비지콜렉터 #Garbage Collector
- 스프링
- spring cloud sleuth
- 카카오 코테
- 디자인패턴
- behavior parameterization
- okhttp3
- 코테
- WORE
- 신규 아이디 추천
- 2019 Kakao Blind
- 모던 자바 인 액션
- Spring
- Java #JIT #JVM
- jvm
- 2021
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
글 보관함