Skip to content

Commit

Permalink
이슈 #405에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 2, 2024
1 parent 2970119 commit 79cc23f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Programmers/프로세스.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <string>
#include <vector>
#include <queue>

using namespace std;

int solution(vector<int> priorities, int location) {
queue<pair<int, int>> q;
priority_queue<int> pq;

for (int i = 0; i < priorities.size(); i++) {
q.push({i, priorities[i]});
pq.push(priorities[i]);
}

int count = 0;
while (!q.empty()) {
auto temp = q.front();
q.pop();

if (pq.top() == temp.second) {
count++;
pq.pop();
if (temp.first == location) {
return count;
}
} else {
q.push(temp);
}
}

return count;
}

0 comments on commit 79cc23f

Please sign in to comment.