stack 으로 풀라 했지만 time의 차이가 없어 보이길래 그냥 반복문으로 풀었음.
#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 time = 0;
for (int j = i + 1; j < prices.size(); j++)
{
time++;
if (prices[i] > prices[j])
break;
}
answer.push_back(time);
}
return answer;
}
'Coding_Test 연습 > Programmers' 카테고리의 다른 글
[프로그래머스] (C++) LV2 전력망을 둘로 나누기 (0) | 2022.06.02 |
---|---|
[프로그래머스] (C++) LV2 구명보트 (0) | 2022.06.01 |
[프로그래머스] (C++) LV2 영어 끝말잇기 (0) | 2022.06.01 |
[프로그래머스] (C++) LV2 삼각 달팽이 (0) | 2022.06.01 |
[프로그래머스] (C++) LV2 2개 이하로 다른 비트 (0) | 2022.06.01 |