import java.util.*; class Solution { private long[] getCrsPositions(int[] a, int[] b) { double A = a[0], B = a[1], E = a[2], C = b[0], D = b[1], F = b[2]; double x = 0; if (A * D - B * C == 0) { return null; } if (((B * F) - (E * D)) != 0 && ((A * D) - (B * C)) != 0) { x = ((B * F) - (E * D)) / ((A * D) - (B * C)); } double y = 0; if (((E * C) - (A * F)) != 0 && ((A * D) - (B * C)) != 0) { y = (..
import java.util.*; class Solution { public int[] solution(int n) { int[][] arr = new int[n][n]; int nu = 1; int d = 0; int w = 0; int mn = 0; int turnPoint = n; int turnCount = 1; String[] modes = { "down", "right", "up" }; int endPoint = 0; for (int q = 1; q < n + 1; q++) { endPoint += q; } while (true) { if (modes[mn].equals("down")) { arr[d][w] = nu; d += 1; } else if (modes[mn].equals("righ..
def solution(cap, n, deliveries, pickups): answer = 0 deli_cap = 0 pick_cap = 0 for i in range(n-1, -1, -1): count = 0 deli_cap -= deliveries[i] pick_cap -= pickups[i] while deli_cap < 0 or pick_cap < 0: deli_cap += cap pick_cap += cap count += 1 answer += (i + 1) * 2 * count return answer
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..