본문 바로가기

Beakjoon&프로그래머스/Java466

[프로그래머스/Java] 크기가 작은 부분 문자열 -Codeclass Solution { public int solution(String t, String p) { int answer = 0; int pLen = p.length(); long pInt = Long.parseLong(p); for (int i = 0; i = n) answer++; } return answer; }} 2025. 2. 25.
[프로그래머스/Java] 최대공약수와 최소공배수 -Codeclass Solution { public int[] solution(int n, int m) { return new int[] {gcd(n, m), n * m / gcd(n, m)}; } public static int gcd(int num1, int num2) { return num2 == 0 ? num1 : gcd(num2, num1 % num2); }} 2025. 2. 25.
[프로그래머스/Java] 같은 숫자는 싫어 -Codeimport java.util.*;public class Solution { public int[] solution(int []arr) { List answer = new ArrayList(); int now = -1; for (int n : arr) { if (now != n) { now = n; answer.add(n); } } return answer.stream().mapToInt(Integer::intValue).toArray(); }} 2025. 2. 25.
[프로그래머스/Java] 직사각형 별찍기 -Codeimport java.util.Scanner;class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); for (int i = 0; i 2025. 2. 25.
[프로그래머스/Java] K번째수 -Codeimport java.util.*;class Solution { public int[] solution(int[] array, int[][] commands) { List answer = new ArrayList(); for (int[] command : commands) { int[] arr = Arrays.stream(Arrays.copyOfRange(array, command[0] - 1, command[1])) .sorted().toArray(); answer.add(arr[command[2] - 1]); } return answer.stream(.. 2025. 2. 25.
[프로그래머스/Java] 행렬의 덧셈 -Codeclass Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int row = arr1.length, col = arr1[0].length; int[][] answer = new int[row][col]; for (int i = 0; i 2025. 2. 24.