function solution(name) { // name = "AAAACB" // name = 'AABAAAAAAABBB' const arr = name.split(''); let move = arr.length - 1; for (let i = 0; i < arr.length; i++) { const from = 'A'.charCodeAt(0); const to = arr[i].charCodeAt(0); const u_distance = to - from const d_distance = 'Z'.charCodeAt(0) - to + 1; count += Math.min(d_distance, u_distance); if (i < arr.lengt..
class Solution { public static int answer = 0; public int solution(int[] numbers, int target) { recur(numbers, 0, 0, target); return answer; } // DFS -> 재귀 public void recur(int[] numbers, int count, int r, int target) { // count: 탐색깊이 체크 if (numbers.length > count) { int r_1 = r + numbers[count]; int r_2 = r - numbers[count]; count++; // 탐색이 완료되지 않았기 때문에 재귀실행 recur(numbers, count, r_1, target);..
class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = new int[arr1.length][arr2[0].length]; // arr1 행렬 열 순회 for (int i = 0; i < arr1.length; i++) { // arr2 행렬 행 순회 for (int j = 0; j < arr2[0].length; j++) { int sum = 0; // arr1 행렬 행의 각 값과 arr1 행렬의 각 열값을 곱해준다. for (int k = 0; k < arr1[i].length; k++) { sum += arr1[i][k] * arr2[k][j]; } answer[i][j] = sum; } } ret..
function solution(n) { let arr = [0, 1] let count = 0; // (A+B)%C = ((A%C)+(B%C))%C while (count 나머지를 반환하는 공식으로 처리 return arr[0] % 1234567; } 문제링크
function solution(users, emoticons) { const answer = []; const permutations = []; const discounts = [10, 20, 30, 40]; const leng = emoticons.length - 1; // 중복순열을 통한 모든 경우의 수 수집 const getPermutations = function (discounts, depth, state) { if (depth > leng) { permutations.push([...state]); return; } for (var i = 0; i < discounts.length; i++) { const discount = discounts[i]; getPermutations(discoun..
import java.util.*; class Solution { public int solution(int[][] targets) { // 종료시점 기준 배열정렬 Arrays.sort(targets, new Comparator() { public int compare(int[] s1, int[] s2) { if (s1[1] == s2[1]) { return s2[0] - s1[0]; } else { return s1[1] - s2[1]; } } }); int start = 0; int end = 0; int answer = 0; for (int i = 0; i < targets.length; i++) { int r1 = targets[i][0]; int r2 = targets[i][1]; // 첫 탄환..
function solution(s){ var braceCount = 0; var answer = true; s.split("").forEach(b => { if (b === "(") { braceCount += 1; } else { braceCount -= 1; } if (braceCount 0) { answer = false } return answer; } 코딩테스트 연습 - 올바른 괄호 | 프로그래머스 스쿨 (programmers.co.kr)
import java.util.*; import java.util.stream.*; class Solution { public int solution(int[] scoville, int K) { PriorityQueue pq = new PriorityQueue(); for (int s : scoville) { pq.add(s); } int count = 0; while (true) { // 모든 음식의 스코빌 지수를 K 이상으로 만들 수 없는 경우 if (pq.size() == 1 && pq.peek() = K) { return count; // 모든 음식의 스코빌 지수가 K 이상이..