programmers 79

[programmers] K번째수

문제https://school.programmers.co.kr/learn/courses/30/lessons/42748 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; for (int i = 0; i commands를 순회하며 다음 과정을 거친다. 1. i번째 숫자부터 j번째 숫자까지 자르기2. 자른 배열을 정렬3. k번째 있는 수를 answer에 저장 ..

[programmers] 완주하지 못한 선수

문제https://school.programmers.co.kr/learn/courses/30/lessons/42576 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java) 1) HashMap import java.util.*;class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; HashMap map = new HashMap(); for (String str : participant) { if (!map.containsKey(str)) { map.p..

[programmers] 디스크 컨트롤러

문제https://school.programmers.co.kr/learn/courses/30/lessons/42627 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int solution(int[][] jobs) { int answer = 0; Arrays.sort(jobs, new Comparator() { @Override public int compare(int[] o1, int[] o2) { return o1[0] - o2[0]; } }); PriorityQueue queue = ..

[programmers] 이중우선순위큐

문제https://school.programmers.co.kr/learn/courses/30/lessons/42628 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 이 문제를 풀면서 예전에 풀었던 문제가 기억이 안 나서 참고했다https://melody-coding.tistory.com/318 [Baekjoon] 7662_이중 우선순위 큐Gold IV문제(출처: https://www.acmicpc.net/problem/7662) 문제 풀이 & 생각 처음에는 최댓값과 최솟값을 관리하기 위해 우선순위 큐를 2개 선언해서 오름차순, 내림차순 순으로 정렬해서 사용했다. 시간제melody-coding.tistory.co..

[programmers] 베스트앨범

문제https://school.programmers.co.kr/learn/courses/30/lessons/42579 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int[] solution(String[] genres, int[] plays) { int[] answer; HashMap total = new HashMap(); HashMap> songs = new HashMap(); for (int i = 0; i ()); } songs.get(genres[i]).add(new int[] { i, ..

[programmers] 정수 삼각형

문제https://school.programmers.co.kr/learn/courses/30/lessons/43105 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(int[][] triangle) { int answer = 0; int dp[][] = new int[triangle.length][triangle[triangle.length - 1].length]; dp[0][0] = triangle[0][0]; for (int i = 0; i 거쳐간 숫자의 합을 구하기 위해 dp 배열을 선언한다. 0번째 행에는 원..

[programmers] 가장 먼 노드

문제https://school.programmers.co.kr/learn/courses/30/lessons/49189 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int solution(int n, int[][] edge) { int answer = 0; ArrayList> list = new ArrayList(); for (int i = 0; i ()); } for (int i = 0; i > list, int[] depth) { Queue queue = new LinkedList(); queue..

[programmers] 단어 변환

문제https://school.programmers.co.kr/learn/courses/30/lessons/43163 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { static class Word { String word; int cnt; public Word(String word, int cnt) { this.word = word; this.cnt = cnt; } } public int solution(String begin, String target, String[] words) { int answer =..

[programmers] 네트워크

문제https://school.programmers.co.kr/learn/courses/30/lessons/43162 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int solution(int n, int[][] computers) { int answer = 0; boolean visited[] = new boolean[n]; for (int i = 0; i queue = new LinkedList(); queue.add(idx); while (!queue.isEmpty()) { int num =..

[programmers] 타겟 넘버

문제https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { static int answer; public int solution(int[] numbers, int target) { answer = 0; dfs(numbers, 0, target, 0); return answer; } private void dfs(int[] numbers, int sum, int target, int idx) { if (idx == numbers.length) { ..