728x90
SMALL

C#

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;

public class Solution {
    public int solution(int[] priorities, int location)
    {
        int answer = 0;
        Queue<KeyValuePair<int, int>> que = new Queue<KeyValuePair<int, int>>();
        
        for(int i = 0; i < priorities.Length; i++)
        {
            que.Enqueue(new KeyValuePair<int, int>(i, priorities[i]));
        }
        
        while(true)
        {
            int Max = que.Max(x=>x.Value);
            var deque = que.Dequeue();


            if (deque.Value == Max)
            {
                if (deque.Key == location) return answer + 1;
                else
                {
                    answer++;
                    continue;
                }
            }
            que.Enqueue(deque);
        }
    }
}

 

 

 

// Enqueue가 push 같은 느낌이고

// Dequeue가 pop 같은 느낌이다.

// 큐는 FIFO 처음에 들어간 게 처음에 나간다는 개념이다.

 

 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;

public class Solution {
    public int solution(int[] priorities, int location) {
        int answer = 0;
            Queue<int> que = new Queue<int>(Enumerable.Range(0, priorities.Length));
            List<int> max = new List<int>(priorities);

            while (que.Count > 0) 
            {
                int document = que.Dequeue();

                if (max.Max() <= priorities[document])
                {
                    answer++;
                    max.Remove(priorities[document]);

                    if (document == location)
                        break;
                }
                else
                    que.Enqueue(document);
            }

            return answer;
    }
}
728x90

설정

트랙백

댓글