
아래는 프로그래머스에서 제공한 문제 설명입니다.
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다.
또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 기능보다 먼저 개발될 수 있고, 이때 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포됩니다.
먼저 배포되어야 하는 순서대로 작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때 각 배포마다 몇 개의 기능이 배포되는지를 return 하도록 solution 함수를 완성하세요.
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<int> answer = new List<int>();
List<int> days = new List<int>();
for(int i = 0; i < progresses.Length; i++)
{
int progress = progresses[i];
int day = 0;
while(progress < 100)
{
progress += speeds[i];
day++;
}
days.Add(day);
}
for(int i = 0; i < days.Count; i++)
{
int count = 1;
for(int j = i + 1; j < days.Count; j++)
{
if(days[i] >= days[j])
count++;
else
break;
}
i += count - 1;
answer.Add(count);
}
return answer.ToArray();
}
}
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<int> answer = new List<int>();
Queue<int> days = new Queue<int>();
for(int i = 0; i < progresses.Length; i++)
{
int progress = progresses[i];
int day = 0;
while(progress < 100)
{
progress += speeds[i];
day++;
}
days.Enqueue(day);
}
while(days.Count > 0)
{
int day = days.Dequeue();
int count = 1;
while(days.Count > 0 && days.Peek() <= day)
{
count++;
days.Dequeue();
}
answer.Add(count);
}
return answer.ToArray();
}
}
Queue를 사용한 풀이가 좀 더 직관적이다.