일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- @transactional
- netty
- S3
- 백준
- Invalid property 'principal.username' of bean class
- ObjectOptimisticLockingFailureException
- 우아한 테크러닝
- 알고리즘
- 멀티모듈 테스트컨테이너
- TestContainers
- multimodule testcontainers
- Spring Cloud Gateway
- redissonlock aop
- kotest testcontainers
- aop
- 소수찾기 java
- interface
- springsecurity
- RefreshToken
- 형상관리
- 낙관적 락 롤백
- spring aop
- java
- AccessToken
- spring DI
- ObjectOptimisticLockingFailureException 처리
- 낙관적 락 재시도
- OptimisticLock
- DI
- jpa
- Today
- Total
조급하면 모래성이 될뿐
[프로그래머스] 기능개발 본문
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42586
코딩테스트 연습 - 기능개발 | 프로그래머스
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 기능보다 먼저 개발될 수 있고, 이때 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포됩니다. 먼저 배포되어야 하는 순서대로 작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때 각 배포마다 몇
programmers.co.kr
나의 풀이
우선 입력 값 진행상황(progresses)와 진행속도(speeds)를 가지고 걸리는 소요기간을 구해주었다.
식은 [ ( 100-진행상황 ) / 진행속도 ] 이고 [ ( 100-진행상황 ) % 진행속도 ] 가 0이아닌경우에는 +1씩해주었다.
ex) 진행상황 93 , 속도1인 경우
7 % 1 = 0 이다. 이때는 소요기간이 7일이 맞다.
ex) 진행상황30 , 속도30인 경우
70 % 30 = 0이아니다. 이때 [ 70 / 30 = 2.xx ]의 값을 가지게된다. 0.xx일을 처리하기 위해 하루를 더 쓴다.
구한 소요시간을 순서대로 Queue에 넣어주었다.
현재 progresse를 처리하면서 소요시간이 더 작은 프로세스가 있으면 Queue에서 하나씩 빼주면서 처리한다.
( 더 작은 프로세스가 없는 경우에는 배포1번이 default로 수행되기 때문에 cnt의 초기 값은 1로 주었다. )
Queue에 담긴 값을 배열로 변경해서 최종 return해주었다.
코드
package Programmers.Level2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class FucntionDevelope {
public static void main(String[] args) {
int[] progresses = {
93,93,93
};
int[] speeds = {
1,1,1
};
int[] answer = solution(progresses,speeds);
System.out.println(Arrays.toString(answer));
}//main
public static int[] solution(int[] progresses, int[] speeds) {
int[] answer = {};
Queue<Integer> periods = new LinkedList<Integer>();
// 평균 소요기간을 구해준다.
for ( int i = 0 ; i < speeds.length; i ++ ) {
int value = (100-progresses[i]) / speeds[i];
if ( (100-progresses[i]) % speeds[i] != 0 ) value++;
periods.add(value);
}
List<Integer> result = new ArrayList<Integer>();
while( !periods.isEmpty() ) {
int cnt = 1 ;
int period = periods.poll();
while( !periods.isEmpty() && period >= periods.peek()) {
periods.poll();
cnt++;
}
result.add(cnt);
}
answer = new int[result.size()];
for ( int i = 0 ; i < answer.length; i++ ) {
answer[i] = result.get(i);
}
return answer;
}
}//class
제출 결과
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스]조이스틱 (5) | 2019.11.07 |
---|---|
[프로그래머스]큰 수 만들기 (0) | 2019.11.06 |
[프로그래머스]쇠막대기 (0) | 2019.11.05 |
[프로그래머스] 124 나라의 숫자 (0) | 2019.11.05 |
[프로그래머스]다리를 지나는 트럭 (0) | 2019.11.04 |