Coding
-
[프로그래머스]모의고사Coding 2021. 6. 29. 21:01
* 알게된점 1.TreeMap의 경우 가장 큰 키를 반환하는 메소드가 존재함 - lastkey() -그 이외에 higerKey(K key), floorkey(K key), ceilingKey(K key), firstKey() 존재함 2. 다른 사람 풀이 중 3가지 숫자의 max값을 구하는 방법 int max = Math.max(hit[0], Math.max(hit[1], hit[2])); TreeMap map = new TreeMap(); int[][] players = { { 1, 2, 3, 4, 5 }, { 2, 1, 2, 3, 2, 4, 2, 5 }, { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 } }; int arr_length; for (int i = 0; i < players.len..
-
[프로그래머스] 이중우선순위 큐Coding 2021. 6. 25. 01:06
*알아낸 점* 1. que.remove()를 통해 내가 원하는 값을 que에서 삭제 가능 2. 애초에 answer = {0,0}를 넣어 놔서, 아무것도 안들어가면 그냥 answer만 반환하면 됨 3. 내 코드에는 쓰지 않았지만, 아래와 같이 2개의 큐에서 삭제하는 방법도 있다 int max = reverse_pq.poll(); pq.remove(max); int[] answer = { 0, 0 }; Queue orderedQue = new PriorityQueue(); Queue reversedOrderedQue = new PriorityQueue(Collections.reverseOrder()); for (String str : operations) { StringTokenizer st = new St..
-
[프로그래머스] 디스크 컨트롤러Coding 2021. 6. 20. 07:20
방법이 잘 떠오르지 않아서 구글링으로 해결... i) pollfirst() 나 poll()이나 여기 문제에서는 영향이 없어서 poll()로 써봤고 ii) LinkedList사용시 참조 변수를 List로 하지 않은 이유는.. 아래에서 peek()를 사용해야 해서 그랬음 class Job { int requestTime; int workingTime; public Job(int requestTime, int workingTime) { this.requestTime = requestTime; this.workingTime = workingTime; } } public int solution(int[][] jobs) { LinkedList wait = new LinkedList(); Queue que = new..
-
[프로그래머스]프린터Coding 2021. 6. 18. 03:18
public static int solution(int[] priorities, int location) { int answer = 0; Queue que = new LinkedList(); for(int i = 0; i < priorities.length; i++) { que.offer(new Paper(i,priorities[i])); } while(!que.isEmpty()) { boolean flag = false; int comp = que.peek().priority; for(Paper q : que) { if(comp < q.priority) { flag = true; break; } } if(flag) { que.offer(que.poll()); } else { if(que.poll().l..
-
[프로그래머스]기능개발Coding 2021. 6. 16. 18:58
List answer = new LinkedList(); int tempCount; while (true) { if (progresses[progresses.length - 1] == -1) { break; } tempCount = 0; for (int i = 0; i = 100) { progresses[0] = -1; tempCount++; } // 제일 처음 인덱스가 아니고 && 앞에 progress 값이 -1일 경우 && speed>= 100 if(i != 0 && progresses[i-1] == -..
-
[프로그래머스] 베스트앨범Coding 2021. 6. 14. 06:42
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; class Solution { public int[] solution(String[] genres, int[] plays) { List answer = new ArrayList(); Map hm = new HashMap(); for (int i = 0; i < genres.length; i++) { hm.put(genres[i], hm.getOrDefault(genres[i], 0) + plays[i]); } List al = new ArrayList(hm.keySet()); ..