프로그래머스 15

[프로그래머스] 이중 우선 순위 큐(자바) / 힙

문제 제한 사항 및 입출력 문제풀이 import java.util.*; class Solution { public int[] solution(String[] operations) { int[] answer = new int[2]; PriorityQueue pq1 = new PriorityQueue(); PriorityQueue pq2 = new PriorityQueue(Collections.reverseOrder()); String[] tmp; for(int i = 0 ; i < operations.length;i++){ tmp = operations[i].split(" "); if(pq1.size()==0 && tmp[0].equals("D"))continue; if(tmp[0].equals("I"))..

[프로그래머스] 디스크 컨트롤러(자바) /Heap

문제 설명 제한사항 입력&출력 문제풀이 import java.util.*; class Solution { static class job { int request; int time; public job(int request, int time) { this.request = request; this.time = time; } } public int solution(int[][] jobs) { int answer = 0; LinkedList works = new LinkedList(); PriorityQueue pq = new PriorityQueue(new Comparator() { @Override public int compare(job i, job j) { return i.time - j.time; }..

[프로그래머스] 프린터(자바) / 자료구조

문제 설명 제안사항 및 입출력 문제 풀이 import java.util.*; class Solution { static class task{ int prior; int loc; public task(int prior,int loc){ this.prior=prior; this.loc=loc; } } public int solution(int[] priorities, int location) { int answer = 0; Queue q = new LinkedList(); for(int i = 0 ; i < priorities.length ; i++){ q.add(new task(priorities[i],i)); } while(true){ task tmp = q.poll(); boolean flag = fa..

[프로그래머스] 베스트 앨범(자바) / Hash

문제 설명 제한사항 입출력 문제풀이 import java.util.*; class Solution { public int[] solution(String[] genres, int[] plays) { int[] answer = {}; ArrayList answers = new ArrayList(); HashMap hm = new HashMap(); for(int i = 0 ; i < genres.length;i++){ if(hm.containsKey(genres[i])==true){ hm.put(genres[i],hm.get(genres[i])+plays[i]); continue; } hm.put(genres[i],plays[i]); } ArrayList arr = new ArrayList(hm.keySe..