Recent Posts
«   2024/12   »
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 28
29 30 31
Today
Total
관리 메뉴

Try

[Programmers/C++] 탑 본문

Algorithm/Programmers

[Programmers/C++] 탑

HAS3ONG 2018. 11. 15. 15:46

출처

https://programmers.co.kr/learn/courses/30/lessons/42588




소스



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
28
29
30
31
32
33
34
35
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
vector<int> solution(vector<int> heights) 
{
    vector<int> answer;
    for(int i = heights.size()-1; i>=0; i--)
    {
        for(int j = i-1; j>=0; j--)
        {
            if(i == 0)
            {
                answer.push_back(0);
                break;
            }
            else if(heights[j] > heights[i] && i != j)
            {
                answer.push_back(j+1);
                break;
            }
            else if (j==0)
            {
                answer.push_back(0);
                break;
            }
           
        }
    }
    answer.push_back(0);
    reverse(answer.begin(), answer.end());
    return answer;
}
cs


'Algorithm > Programmers' 카테고리의 다른 글

[Programmers/C++] 124 나라의 숫자  (0) 2018.11.18
[Programmers/C++] 기능개발  (0) 2018.11.15
[Programmers/C++] 소수의 합  (0) 2018.11.15
[Programmers/C++] 카펫  (0) 2018.11.12
[Programmers/C++] 최빈값 구하기  (0) 2018.11.12
Comments