https://school.programmers.co.kr/learn/courses/30/lessons/131704
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
int solution(vector<int> order) {
int answer = 0;
stack<int> s;
priority_queue<int, vector<int>, greater<int>> q(order.begin(), order.end());
for (size_t i = 0; i < order.size();)
{
const auto find = order[i];
if (find < q.top() && !s.empty() && find != s.top()) break;
if (!s.empty() && find == s.top()) s.pop(), ++i, ++answer;
else if (find == q.top()) q.pop(), ++i, ++answer;
else
{
if (find > q.top())
{
s.push(q.top());
q.pop();
}
}
}
return answer;
}
[level 2] Title: 택배상자, Time: 88.68 ms, Memory: 42.2 MB -BaekjoonHub · developeSHG/Algorithm-Baekjoon_Programmers@44b462
developeSHG committed Jul 26, 2023
github.com
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (월간 코드 챌린지 시즌1) Lv 2. 삼각 달팽이 (0) | 2023.07.28 |
---|---|
[Programmers] (탐욕법(Greedy)) Lv 2. 큰 수 만들기 (0) | 2023.07.27 |
[Programmers] (월간 코드 챌린지 시즌1) Lv 2. 쿼드압축 후 개수 세기 (0) | 2023.07.25 |
[Programmers] (완전탐색) Lv 2. 소수 찾기 (0) | 2023.07.24 |
[Programmers] (정렬) Lv 2. 가장 큰 수 (0) | 2023.07.24 |
댓글