728x90
https://school.programmers.co.kr/learn/courses/30/lessons/42587
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
using System;
using System.Collections.Generic;
public class Solution {
public int solution(int[] priorities, int location) {
int answer = 0;
Queue<(int, int)> queue = new Queue<(int, int)>(); //index, priority
for (int i = 0; i < priorities.Length; i++){
queue.Enqueue((i, priorities[i])); //(0,2) (1,1) (2,3) (3,2)
}
Array.Sort(priorities);
Array.Reverse(priorities);
while(true){
var (a, b) = queue.Dequeue();
if (b == priorities[answer]){
answer++;
if (a == location) return answer;
}
else{
queue.Enqueue((a, b));
}
}
}
}
728x90
'공부 > C#' 카테고리의 다른 글
[C#] 프로그래머스 스택/큐 - 올바른 괄호 (0) | 2025.03.09 |
---|---|
[C#] 프로그래머스 스택/큐 - 기능개발 (0) | 2025.03.09 |
[C#] 코딩테스트에서 쓰는 함수 / 변수 (0) | 2025.03.07 |
[C#] 프로그래머스 백트래킹 - 피로도 (0) | 2025.03.07 |
[C#] 프로그래머스 백트래킹 - 소수 찾기 (0) | 2025.03.07 |