프로그래머스 탑 C++ 풀이
https://programmers.co.kr/learn/courses/30/lessons/42588
// 일단 answer배열 heights 사이즈만큼 0으로 resize 해주고
// i는 num-1부터 하고 j = 0부터 시작해서 j가 오른쪽으로 점점 가니까 값 갱신해 주게 되니까 결국에는 i와 가장 가까운 쪽의 탑이 됨
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> heights) {
vector<int> answer;
int num = heights.size();
answer.resize(num, 0);
for (int i = num -1; i >= 0; i--){
for (int j = 0; j < i; j++){
if (heights[i] < heights[j])
answer[i] = j+1;
}
}
return answer;
}
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 기능개발 (0) | 2023.07.07 |
---|---|
[프로그래머스] 다리를 지나는 트럭 (0) | 2023.07.07 |
[프로그래머스] 베스트앨범 (0) | 2023.07.07 |
[프로그래머스] 위장 (0) | 2023.07.06 |
[프로그래머스] 전화번호 목록 (0) | 2023.07.06 |