여름의 서재
[프로그래머스] 기능개발 (파이썬 & 자바) 본문
728x90
📕 문제
https://programmers.co.kr/learn/courses/30/lessons/42586
코딩테스트 연습 - 기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는
programmers.co.kr
💡 풀이법
- Python
from collections import deque
def solution(progresses, speeds):
answer = []
progresses, speeds = deque(progresses),deque(speeds)
while progresses:
n = 0
for i in range(len(progresses)):
progresses[i] += speeds[i]
while progresses and progresses[0] >= 100:
progresses.popleft()
speeds.popleft()
n += 1
if n != 0:
answer.append(n)
return answer
- Java
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<Integer> ans = new ArrayList<>();
Deque<Integer> p = new ArrayDeque<>();
Deque<Integer> s = new ArrayDeque<>();
for (int i = 0; i < progresses.length; i++) {
p.offer(progresses[i]);
s.offer(speeds[i]);
}
int n = 1;
while (p.size() > 0) {
int cnt = 0;
while (p.size() > 0) {
if (p.getFirst() + s.getFirst()*n >= 100) {
p.pollFirst();
s.pollFirst();
cnt++;
if (p.size() == 0) {
ans.add(cnt);
}
} else {
if (cnt > 0) {
ans.add(cnt);
}
break;
}
}
n++;
}
int[] answer = new int[ans.size()];
for (int i = 0; i < ans.size(); i++) {
answer[i] = ans.get(i);
}
return answer;
}
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 튜플 (파이썬 & 자바) (0) | 2021.12.10 |
---|---|
[프로그래머스] 가장 먼 노드 (파이썬 & 자바) (0) | 2021.12.08 |
[프로그래머스] 불량 사용자 (0) | 2021.12.07 |
[프로그래머스] 큰 수 만들기 (0) | 2021.12.07 |
[프로그래머스] 멀쩡한 사각형 (0) | 2021.11.17 |
Comments