https://school.programmers.co.kr/learn/courses/30/lessons/154539
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <bits/stdc++.h>
using namespace std;
vector<int> solution(vector<int> numbers) {
vector<int> answer(numbers.size(), -1);
std::stack<std::pair<int, int>> st;
for (int i = 0; i < numbers.size(); ++i){
while(!st.empty() && st.top().first < numbers[i]){
auto top = st.top(); st.pop();
answer[top.second] = numbers[i];
}
st.push({numbers[i], i});
}
return answer;
}
'프로그래머스 문제풀이 > LEVEL 2' 카테고리의 다른 글
[C++] 프로그래머스 문제풀이 LEVEL 2 숫자 변환하기 (0) | 2023.07.05 |
---|---|
[C++] 프로그래머스 문제풀이 LEVEL 2 2 x n 타일링 (0) | 2023.07.05 |
[C++] 프로그래머스 문제풀이 LEVEL 2 모음 사전 (0) | 2023.07.05 |
[C++] 프로그래머스 문제풀이 LEVEL 2 스킬트리 (0) | 2023.07.05 |
[C++] 프로그래머스 문제풀이 LEVEL 2 방문 길이 (0) | 2023.07.05 |