프로그래머스_C#/Level_2

[프로그래머스 C#] 주식가격

최애뎡 2021. 12. 12. 18:37
728x90
반응형

https://programmers.co.kr/learn/courses/30/lessons/42584

 

코딩테스트 연습 - 주식가격

초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,00

programmers.co.kr

using System;

public class Solution
{
    public int[] solution(int[] prices)
    {
        int length = prices.Length;
        int[] answer = new int[length];

        for (int i = -1; ++i < length;)
            for (int j = i; ++j < length;)
            {
                answer[i] += 1;

                if (prices[j] < prices[i])
                    break;
            }

        return answer;
    }
}
반응형