Programmers
-
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..
-
Programmers LV.2 위장Programmers 2020. 12. 17. 21:06
처음에는 옷 종류 / 갯수를 별도의 Map 넣어서 처리하도록 계산하려고 하였으나 아무것도 안입엇을 경우, 각 종류별로 안입엇을 경우에 대한 경우의 수가 필요해서 아래와 같이 작업함 @org.junit.Test public void test(){ String[][] clothes = {{"yellow_hat", "headgear"},{"blue_sunglasses","eyewear"},{"green_turban", "headgear"}}; Map clotheType = new HashMap(); int answer = 1; for(String[] clothe : clothes){ clotheType.put(clothe[1] , clotheType.getOrDefault(clothe[1],0) +1); } ..
-
Programmers LV.2 전화번호 목록Programmers 2020. 12. 16. 22:55
2중포문을 사용하지 않고도 처리가 가능 할 줄 알고 별에 별 시물레이션을 돌려봤지만, 명확한 답을 찾지 못하여서 진행 처음엔 향상된 for 문을 사용하는걸 즐겨쓰는데, for(String phone : phone_book) { for(String equlsePhone : phone_book) if(!phone.equlse(equlsePhone) } 위와 같이 처리하는게 더 빠른지 궁금했는데, 결국 한번 더 for문을 돈다는게 오래걸린 다는 것을 확인하고, 처리하였다. 문제를 명확히보지않고 "접두어"가 아닌 indexOf로 해결하면 되겠지 하고 넘겼다가, 접두어 항목을 다시보고 startsWith로 변경하였다. import java.util.*; class Solution { public boolean s..
-
Programmers LV.1 완주하지 못한 선수Programmers 2020. 12. 16. 19:27
이번 코딩테스트를 공부하면서, 차근차근 보자는 생각으로 진행하였다, 해당 문제는 Hash 를 가지고 해결하라는 문구가 써있었지만, 원래 하던 개발 방식적으로 우선적으로 접근해보기로 하였다. List으로 constains를 이용하여 존재여부를 통하여 처리 할 수 있도록 진행하려 하였으나, 효율성 면에서 부족하단 평가를 받았다. import java.util.*; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; List completPeopleList = new ArrayList(); List participantPeopleList = new ArrayList(); fo..