초 단위로 기록된 주식가격이 담긴 배열
prices가 매개변수로 주어질 때,
가격이 떨어지지 않은 기간은 몇 초인지를return하도록solution함수를 완성하세요.
public class StockPriceAnalyzer
{
public static int[] Solution(int[] prices)
{
int[] answer = new int[prices.Length];
for (int i = 0; i < prices.Length; i++)
{
int price = prices[i];
int count = 0;
for (int j = i + 1; j < prices.Length; j++)
{
count++;
if (prices[j] < price)
break;
}
answer[i] = count;
}
return answer;
}
}
price 해당 시점에서 확인해야하는 가격과 그 이후 시간에서의 가격을 비교count++;
if (prices[j] < price)
break;
count에 1을 더함answer에 저장해 반환