bdfgdfg

[레벨 2] 주식가격 본문

코딩테스트/프로그래머스

[레벨 2] 주식가격

marmelo12 2021. 9. 29. 14:01
반응형
#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> prices) {
    vector<int> answer;
    bool exit;
    int count,Len = prices.size(),i,j;
    for(i = 0; i < Len; ++i)
    {
        count = 1;
        for(j = i + 1; j < Len - 1; ++j)
        {
            if(prices[i] > prices[j])
                break;
            else
                ++count;
        }
        if(j == Len) // 마지막 주가. 비교대상이 없으므로 0
        {
            answer.push_back(0);
            break;
        }
        answer.push_back(count);
    }
    return answer;
}

 

반응형

'코딩테스트 > 프로그래머스' 카테고리의 다른 글

[레벨 2] 더 맵게  (0) 2021.10.16
[레벨 2] 타겟 넘버  (0) 2021.09.30
[레벨 2] 다음 큰 숫자  (0) 2021.09.27
[레벨 2] 땅따먹기  (0) 2021.09.24
[레벨 2] 올바른 괄호  (0) 2021.09.23
Comments