[Programmers] 탑

Time Lapse :7min 39sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <vector>
using namespace std;

vector<int> solution(vector<int> heights) {
int find;
int SIZE = heights.size();
vector<int> answer(heights.size(),0);
for(find = SIZE-2;find>=0;find--)
if(heights[find]>heights[SIZE-1]){
answer[SIZE-1] = find + 1;
break;
}

for(int i=SIZE-2;i>=0;i--){
if(heights[i]==heights[i+1])
answer[i] = answer[i+1];
else{
for(find = i-1; find >= 0; find--){
if(heights[find]>heights[i]){
answer[i] = find+1;
break;
}
}
}
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/top/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.