본문 바로가기

problem solving

[프로그래머스]탑

#include <string>
#include <vector>
 
using namespace std;
 
vector<int> solution(vector<int> heights) {
    vector<int> answer;
    int cur = 0;
    
    vector<int> val;
    for(int i = heights.size() - 1; i >= 0; i--) {
        cur = i - 1;
        while(cur > -1 && heights[i] >= heights[cur]) {
            cur--;
        }
        val.push_back(cur + 1);
    }
    
    for(int i = val.size() - 1; i >= 0; i--) {
        answer.push_back(val[i]);
    }
    
    return answer;
}
cs

'problem solving' 카테고리의 다른 글

[프로그래머스]기능개발  (0) 2020.03.07
[프로그래머스]스킬트리  (0) 2020.03.07
[프로그래머스][1차] 다트 게임  (0) 2020.03.06
[프로그래머스]실패율  (0) 2020.03.06
[프로그래머스][1차] 비밀지도  (0) 2020.03.06