본문 바로가기

자바40

[Lv.2]행렬의 곱셈 package Lv_2; public class 행렬의곱셈 { public static int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = new int[arr1.length][arr2[0].length]; for (int i = 0; i < arr1.length; i++) { for (int j = 0; j < arr2[0].length; j++) { for (int k = 0; k < arr2.length; k++) { answer[i][j] += arr1[i][k] * arr2[k][j]; } } } return answer; } public static void main(String[] args) { int[][] arr1 = new .. 2023. 2. 12.
[Lv.2]괄호 회전하기 package Lv_2; import java.util.LinkedList; import java.util.Stack; public class lv2test { public static boolean chking(LinkedList queue) { Stack stk = new Stack(); if (queue.getFirst() == &#39;]&#39; || queue.getFirst() == &#39;}&#39; || queue.getFirst() == &#39;)&#39;) { return false; } else if (queue.getLast() == &#39;[&#39; || queue.getLast() == &#39;{&#39; || queue.getLast() == &#39;(&#39;) .. 2023. 2. 11.
[Lv.2]캐시 캐시에 대한 개념이 부족해서 공부하고 난 후, 푼 문제이다..(캐시정리, https://sungsikyang92.tistory.com/232) package Lv_2; import java.util.LinkedList; public class 캐시 { public static int solution(int cacheSize, String[] cities) { int answer = 0; //캐시사이즈가 0일때 if (cacheSize == 0) { return cities.length * 5; } //큐를 위한 링크드리스트 LinkedList cache = new LinkedList(); for (int i = 0; i < cities.length; i++) { String s = cities[i].to.. 2023. 2. 11.
[Lv.2]멀리 뛰기 package Lv_2; public class 멀리뛰기 { public long solution(int n) { int[] dp = new int[2001]; dp[1] = 1; dp[2] = 2; for (int i = 3; i < dp.length; i++) { dp[i] = ((dp[i - 2] + dp[i - 1]) % 1234567); } return dp[n]; } } 2023. 2. 6.