본문 바로가기

Java717

[프로그래머스/Java] 귤 고르기 -Codeimport java.util.*;class Solution { public int solution(int k, int[] tangerine) { int answer = 0; Map map = new HashMap(); // 값을 map으로 count for (int el : tangerine) { map.put(el, map.getOrDefault(el, 0) + 1); } List keySet = new ArrayList(map.keySet()); // 가장 많이 가지고 있는 크기의 사과 부터 갯수 빼기 위한 정렬 keySet.sort((o1, o2) -> map.ge.. 2025. 11. 18.
[백준/Java] 10426번 기념일 2 -Codeimport java.util.HashMap;import java.util.Map;import java.util.Scanner;public class BOJ10426 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String date = sc.next(); int add = sc.nextInt(); // 년월일 분리 String[] parts = date.split("-"); int year = Integer.parseInt(parts[0]); int month = Integer.parseInt(parts[.. 2025. 11. 18.
[LeetCode/Java] 14. Longest Common Prefix -Codeclass Solution { public String longestCommonPrefix(String[] strs) { int minStrLength = getMinLength(strs); int totalLength = strs.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i 2025. 11. 18.
[LeetCode/Java] 13. Roman to Integer -Codeclass Solution { public int romanToInt(String s) { Map roman = Map.of( 'I', 1, 'V', 5, 'X', 10, 'L', 50, 'C', 100, 'D', 500, 'M', 1000 ); int answer = 0; // 감산시 사용할 변수 int prev = 0; for (int i = s.length() - 1; i >= 0; i--) { int now = roman.get(s.charAt(i)); // 이전 값보다 작으면 빼고 크거나 같으면 더하기 .. 2025. 11. 18.
[백준/Java] 34619번 소대 배정 -Codeimport java.util.Scanner;public class BOJ34619 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int n = sc.nextInt(); int k = sc.nextInt(); // 나눗셈으로 구역 계산 보정을 위한 -1과 +1 int company = (k - 1) / (b * n) + 1; int platoon = (k - 1) % (b * n) / n + 1; Syste.. 2025. 11. 17.
[백준/Java] 33488번 아름다운 수열 -Codeimport java.util.Scanner;public class BOJ33488 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i 처음 문제를 잘못 이해해서 찾아보니 어차피 순서대로 수열을 지정하면 소수 값끼리의 차와 거리의 차가 일치해서 어떠한 경우에도 수열이 있음을 알게 되어서 풀게 되었습니다. 2025. 11. 16.