문제
풀이
2중 for문을 사용했습니다.
처음 for문은 검사할 시점의 주식가격을 결정하고
두번째 for문에서는 첫번째 for문에서 결정된 가격에비해 하락이 있었나 여부를 판단해서 계산합니다.
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> prices) {
vector<int> answer;
for(int i=0; i<prices.size(); i++)
{
int count=0;
for(int j=i+1; j<prices.size(); j++)
{
if(prices[i] <= prices[j])
count++;
else
{
count++;
break;
}
}
answer.push_back(count);
}
return answer;
}
'알고리즘 > 프로그래머스 문제풀이' 카테고리의 다른 글
[C++] 올바른 괄호 (Lv.2) (0) | 2022.09.05 |
---|---|
[C++] 올바른 괄호 (Lv.2) (0) | 2022.09.04 |
[C++] 124 나라의 숫자 (Lv.2) (0) | 2022.09.04 |
[C++] 멀쩡한 사각형 (Lv.2) (0) | 2022.08.30 |
[C++] 단체사진 찍기 (Lv.2) (0) | 2022.08.29 |