<내 코드>
- Java
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<Integer> temp = new ArrayList<>();
List<Integer> result = new ArrayList<>();
for(int i=0; i < progresses.length; i++){
if((100-progresses[i]) % speeds[i] == 0){
temp.add((100-progresses[i]) / speeds[i]);
}else{
temp.add(((100-progresses[i]) / speeds[i]) + 1);
}
}
// 리스트 temp를 비교해 배포마다 몇 개씩 되는지
int cnt = 1;
int ck = temp.get(0);
for(int j=1; j < temp.size(); j++){
if(ck >= temp.get(j)){
cnt += 1;
}else{
result.add(cnt);
ck = temp.get(j);
cnt = 1;
}
if(j == (temp.size()-1)){
result.add(cnt);
}
}
// 리스트를 배열로 바꿔 출력
int[] answer = new int[result.size()];
for(int i=0; i<result.size(); i++){
answer[i] = result.get(i);
}
return answer;
}
}
- Python
def solution(progresses, speeds):
answer = []
temp = []
for i in range(len(progresses)):
days = (100 - progresses[i]) % speeds[i]
if (days) == 0:
temp.append((100 - progresses[i]) // speeds[i])
else:
temp.append((100 - progresses[i]) // speeds[i] + 1)
ck = temp[0]
cnt = 1
for i in range(1, len(temp)):
if ck >= temp[i]:
cnt += 1
else:
ck = temp[i]
answer.append(cnt)
cnt = 1
if i == (len(temp)-1):
answer.append(cnt)
return answer
'알고리즘 문제풀기 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 주식가격 - Python, Java(스택,큐) (0) | 2020.10.19 |
---|---|
[2019 카카오 겨울 인턴십] 튜플 - Python (0) | 2020.09.11 |
[2019 카카오 겨울 인턴십] 크레인 인형뽑기 게임 - Python (0) | 2020.09.11 |
[2020 카카오 인턴십] 수식 최대화 - Python (0) | 2020.09.11 |
[JavaScript] 프로그래머스 - 다리를 지나는 트럭 (0) | 2020.05.11 |