목록분류 전체보기 (152)
개발 공부
코딩테스트 연습 - 해시 - 베스트엘범 https://programmers.co.kr/learn/courses/30/lessons/42579 첫시도. (틀린 답안) sorting까지 완료. 하지만 효율적으로 장르별 2개씩만 가져오는 게 생각이 안나 갈아 엎었다. function solution(genres, plays) { var answer = []; var musicMapArray = []; var totalObj = {}; for(var i = 0 ; i < genres.length ; i ++){ var musicObj = {}; musicObj['number'] = i; musicObj['genre'] = genres[i]; musicObj['count'] = plays[i]; totalObj[..
코딩테스트 연습 - 해시 -위장 https://programmers.co.kr/learn/courses/30/lessons/42578 import java.util.*; class Solution { public int solution(String[][] clothes) { int answer = 0; Map hm = new HashMap(); for(String[] cloth : clothes){ if(hm.get(cloth[1]) == null){ List newList = new ArrayList(); newList.add(cloth[0]); hm.put(cloth[1], newList); }else{ List existList = hm.get(cloth[1]); existList.add(cloth..
코딩테스트 연습 - 정렬 - H-index https://programmers.co.kr/learn/courses/30/lessons/42747 import java.util.*; import java.lang.*; class Solution { public int solution(int[] citations) { int answer = 0; Integer[] integerArr= new Integer[citations.length]; for(int i = 0 ; i < citations.length ; i++){ integerArr[i] = citations[i]; } Arrays.sort(integerArr, Collections.reverseOrder()); int min = Math.min(int..
코딩테스트 연습 - 스택/큐 - 다리를 지나는 트럭 https://programmers.co.kr/learn/courses/30/lessons/42583 import java.util.*; class Solution { class Truck{ int weight; int entry; Truck(int weight,int entry){ this.weight = weight; this.entry = entry; } } public int solution(int bridge_length, int weight, int[] truck_weights) { int answer = 0; Queue waiting = new LinkedList(); Queue bridge = new LinkedList(); for(int..
코딩테스트 연습-정렬-가장 큰 수 https://programmers.co.kr/learn/courses/30/lessons/42746 import java.util.*; class Solution { public String solution(int[] numbers) { String answer = ""; String[] sArray = new String[numbers.length]; for(int i = 0 ; i < numbers.length ; i++){ sArray[i] = numbers[i]+""; } Arrays.sort(sArray, new Comparator(){ @Override public int compare(String o1, String o2){ return (o2+o1).co..
코딩테스트 연습-해시-전화번호 목록 https://programmers.co.kr/learn/courses/30/lessons/42577 class Solution { public boolean solution(String[] phone_book) { boolean answer = true; //길이가 작은것만 접두사가 될 수 있다. for(int i = 0 ; i < phone_book.length ; i++){ for(int j = 0 ; j < phone_book.length ; j++){ if(i!=j && phone_book[i].length()
코딩테스트 연습-깊이/너비 우선 탐색(DFS/BFS)-타겟 넘버 https://programmers.co.kr/learn/courses/30/lessons/43165 class Solution { public int solution(int[] numbers, int target) { int answer = 0; answer = dfs(numbers, 0, 0, target); return answer; } private int dfs(int[] numbers, int current, int sum, int target){ if(current == numbers.length){ if(sum == target){ return 1; }else{ return 0; } } return dfs(numbers, cu..
코딩테스트 연습-힙(Heap)-더 맵게 https://programmers.co.kr/learn/courses/30/lessons/42626 import java.util.*; class Solution { public int solution(int[] scoville, int K) { int answer = 0; Queue pq = new PriorityQueue(scoville.length); for(int s : scoville){ pq.offer(s); } int times = 0; while(pq.peek() 1){ int s1 = pq.poll(); int s2 = pq.poll(); pq.offer(s1+s2*2); times++; } if(pq.size()
코딩테스트 연습-해시-완주하지 못한 선수 https://programmers.co.kr/learn/courses/30/lessons/42576 import java.util.*; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; Map hm = new HashMap(); for(String pt : participant){ if(hm.get(pt) == null){ hm.put(pt,1); }else{ hm.put(pt, hm.get(pt)+1); } } for(String cp : completion){ hm.put(cp, hm.get(cp)-1); } for(Str..
코딩테스트연습-정렬-k번째수 https://programmers.co.kr/learn/courses/30/lessons/42748 import java.util.*; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; for(int i = 0 ; i < commands.length ; i++){ int[] comArr = commands[i]; int[] newArr = new int[comArr[1]-comArr[0]+1]; int index = 0; for(int j = 0; j < newArr.length; j++ ){ //System.out.prin..