#include <string> #include <vector> using namespace std; vector<int> solution(vector<int> prices) { vector<int> answer; for(int i = 0; i < prices.size()-1; i++) { int changeIdx; for(int j = i+1; j < prices.size(); j++) { // 떨어지는 경우 if(prices[i] > prices[j]) { changeIdx = j; break; } // 끝까지 가격이 떨어지지 않는 경우 if(j == prices.size()-1) { changeIdx = j; } } answer.push_back(changeIdx-i); } // 마지막은 무조건 0초 동안 떨어지지 않음 answer.push_back(0); return answer; } | cs |
'Programmers > Level 2' 카테고리의 다른 글
[프로그래머스 2] 탑 (C/C++) (1) | 2019.10.21 |
---|---|
[프로그래머스 2] 124 나라의 숫자 (C/C++) (★) (0) | 2019.10.21 |
[프로그래머스 2] 기능개발 (C/C++) (0) | 2019.10.20 |
[프로그래머스 2] 스킬트리 (C/C++) (0) | 2019.10.20 |
[프로그래머스 2] 괄호 변환 (C/C++) (1) | 2019.10.16 |