목록알고리즘 (15)
개발 공부
코딩테스트 연습-깊이/너비 우선 탐색(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..
코딩테스트 연습-완전탐색- 모의고사 https://programmers.co.kr/learn/courses/30/lessons/42840 import java.util.*; import java.lang.*; class Solution { public int[] solution(int[] answers) { int[] answer = {}; int[] scores = new int[3]; int[] answer1 = {1,2,3,4,5}; int[] answer2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] answer3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; scores[0] = 0; scores[1] = 0; scores[2] = 0; for(int i = 0 ;..