'Coding Test/Programmers' 카테고리의 글 목록 :: 개발공부 (tistory.com)

 

'Coding Test/Programmers' 카테고리의 글 목록

 

hntown43.tistory.com

 

스택/큐 문제이다.

 

import java.util.*;
class Solution {
    public int solution(int[] priorities, int location) {
        int answer = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i : priorities) {
			list.add(i);
		}
		int start = 0;
		while (start < priorities.length) {
			boolean chk = true;
			if (location >= start) {
				for (int i = start + 1; i < priorities.length; i++) {
					if (list.get(start) < list.get(i)) {
						list.add(list.get(start));
						list.remove(start);

						if (location == start)
							location += priorities.length - start - 1;
						else
							location--;

						chk = false;
						break;
					}
				}
			}
			if (chk)
				start++;
		}
		answer = location + 1;
		return answer;
    }
}

+ Recent posts