분류 전체보기
-
Programmers LV.1 K번째수Programmers 2020. 12. 29. 21:10
@org.junit.Test public void kArray(){ int[] array = {1, 5, 2, 6, 3, 7, 4}; int[][] commands = { {2,5,3},{4,4,1},{1,7,3}}; List answerList = new ArrayList(); for(int[] cmd : commands){ List addList =new ArrayList(); //a 배열자르기 첫번째 //b 배열자르기 마지막째 //c c번째 값 int cutFirst = cmd[0]; int cutLast = cmd[1]; int whichValue = cmd[2]; for(int a=cutFirst-1; a< cutLast; a++){ addList.add(array[a]); } Collectio..
-
Programmers LV.3 디스크 컨트롤러Programmers 2020. 12. 29. 15:56
@org.junit.Test public void diskController(){ int[][] jobs ={{0, 10}, {2, 12}, {9, 19}, {15, 17}}; /* int[][] jobs = {{0, 3}, {1, 9}, {2, 6}}; int[][] jobs ={{0, 10}, {2, 10}, {9, 10}, {15, 2}}; int[][] jobs ={{0, 3}, {1, 9}, {2, 6}}; int[][] jobs ={{0, 1}}; int[][] jobs ={{1000, 1000}}; int[][] jobs ={{0, 1}, {0, 1}, {0, 1}}; int[][] jobs ={{0, 1}, {0, 1}, {0, 1}, {0, 1}}; int[][] jobs ={{0, 1}..
-
Programmers LV.2 더 맵게Programmers 2020. 12. 28. 19:20
힙 우선순위로 나열해서 처리하면 될 것 같아서 했는데 테스트케이스 16번에서 에러가 나 원인을 확인해보고있었다. 수정 전 @org.junit.Test public void scoville(){ int[] scovilles = { 1, 2, 3, 9, 10, 12 }; int K = 7; Queue que = new PriorityQueue((o1, o2) -> Integer.compare(o1,o2)); for(int scoville : scovilles){ que.offer(scoville); } int answer = 0; int check = 0; while (que.size() > 1){ if(que.peek() >= K){ answer = check; break; } int o1 = que.po..
-
Programmers LV.2 프린터Programmers 2020. 12. 27. 05:02
지문을 읽으면읽을수록 참 이해가 잘안되는거같다 처음엔 아래와 같이 개발했다가 테스트케이스 단위에서 정확성에서 실패 두두두두두 import java.util.*; class Solution { public int solution(int[] priorities, int location) { int answer = 0; class Print{ Integer priorite = null; Integer location_priorite = null; public Print(Integer priorite,Integer location_priorite){ this.priorite = priorite; this.location_priorite = location_priorite; } public Integer getP..
-
Programmers LV.2 다리를 지나가는 트럭Programmers 2020. 12. 23. 23:49
처음엔 큐를 많이 사용하지 않다버릇하니깐 까먹은 부분이 존재해서 다시 확인 후 개발 하는 작업을 진행하였다. @org.junit.Test public void testBridge(){ int bridge_length = 100; int weight = 100; int[] truck_weights ={10,10,10,10,10,10,10,10,10,10}; /* int bridge_length = 100; int weight = 100; int[] truck_weights ={10}; */ /* int bridge_length = 2; int weight = 10; int[] truck_weights ={7,4,5,6}; */ Queue queue = new LinkedList(); int time = 0..
-
Programmers LV.2 주식가격Programmers 2020. 12. 20. 19:09
해당 문제를 풀기전에 지문이 잘 이해가 되지 않았다. 결국 이해하기로는 prices[0] -> prices[prices.length] 만큼 비교해서 값이 떨어지냐 안떨어지냐를 반복하라는 문구로 이해했다. @org.junit.Test public void jusick(){ int[] prices = {1, 2, 3, 2, 3}; ArrayList answerArray = new ArrayList(); for(int a=0; a < prices.length; a++){ int cnt = 0; if(a == prices.length-1){ answerArray.add(0); } for(int b=(a+1); b< prices.length; b++){ if(prices[a]
-
Programmers LV.3 베스트앨범Programmers 2020. 12. 19. 18:34
처음에 짯을때는 아래와 같이 짯는데, 짜다보니 Value 즉 playCount가 동일할수있을수도 있는데... 라는 의문을 계속맘에 품으면서 작업하다가 결국 최종 코드에서 2/15번 케이스에 막혀서 다시 돌아오기로 하였다 나처럼 2/15번 케이스가 막힐 경우 String[] genres = {"classic","classic","classic","classic","pop"}; int[] plays = {500,150,800,800,2500}; 를 테스트 케이스로 잡고 개발하면 좋을 것 같다. @org.junit.Test public void test(){ // 장르별 재생횟수 총 합 Map genrePlaySumCntMap = new HashMap(); // 장르별 id / play 횟수 Map genre..