전체 글
-
-
-
-
-
-
프로그래머스 > 정렬 > K번째수기타/알고리즘 2021. 8. 8. 14:16
배열 array의 i번째 숫자부터 j번째 숫자까지 자르고 정렬했을 때, k번째에 있는 수를 구하려 합니다. array commands [[i,j,k],[i,j,k]..] return [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] public static int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; int idx = 0; for(int i=0;i
-
-
프로그래머스 > 이중우선순위 큐기타/알고리즘 2021. 8. 7. 22:12
이중 우선순위 큐는 다음 연산을 할 수 있는 자료구조를 말합니다. 명령어수신 탑(높이) I 숫자 큐에 주어진 숫자를 삽입합니다. D 1 큐에서 최댓값을 삭제합니다. D -1 큐에서 최솟값을 삭제합니다. 이중 우선순위 큐가 할 연산 operations가 매개변수로 주어질 때, 모든 연산을 처리한 후 큐가 비어있으면 [0,0] 비어있지 않으면 [최댓값, 최솟값]을 return 하도록 solution 함수를 구현해주세요. List 를 만들어 요소를 Insert 할 때마다 정렬하고, 최소값을 뺄 때는 List 의 맨 앞 요소를 removeFirst , 최대값을 뺄 때는 removeLast로 맨 뒤 요소를 제거한다. public static int[] solution(String[] operations) { in..