본문 바로가기

Java443

[LeetCode/Java] Exclusive Time of Functions -Codeclass Solution { public int[] exclusiveTime(int n, List logs) { Stack stack = new Stack(); int[] answer = new int[n]; int prev = 0; for (String log : logs) { // 로그를 :를 기준으로 나눔 String[] el = log.split(":"); int func = Integer.parseInt(el[0]); String type = el[1]; int timeStamp = Integer.parseInt(el[2]); .. 2025. 11. 27.
[LeetCode/Java] Evaluate Reverse Polish Notation -Codeclass Solution { public int evalRPN(String[] tokens) { Stack stack = new Stack(); List operators = List.of("+", "-", "*", "/"); for (String token : tokens) { // 토큰이 연산자인 경우 if (operators.contains(token)) { int useNum = stack.pop(); int nowNum = stack.pop(); stack.push(calc(token, nowNum, useNum)); .. 2025. 11. 26.
[LeetCode/Java] Build an Array With Stack Operations -Codeclass Solution { public List buildArray(int[] target, int n) { List answer = new ArrayList(); int targetLength = target.length; int targetIndex = 0; for (int now = 1; now = targetLength) { break; } // 일단 리스트에 들어감 answer.add("Push"); // 타겟 인덱스랑 다르면 Pop하고 다음 숫자 찾기 if (target[targetIndex] != no.. 2025. 11. 26.
[백준/Java] 34758번 KUPC에 어서 오세요 -Codeimport java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class BOJ34758 { static int targetX; static int targetY; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readL.. 2025. 11. 26.
[백준/Java] 18766번 카드 바꿔치기 -Codeimport java.io.IOException;import java.util.Arrays;import java.util.Scanner;public class BOJ18766 { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int testCase = sc.nextInt(); for (int i = 0; i 2025. 11. 25.
[백준/Java] 31432번 소수가 아닌 수 3 -Codeimport java.util.Scanner;public class BOJ31432 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] nums = new int[n]; for (int i = 0; i 처음에는 조합 문제인줄 알았지만 아니어서 소수인지 확인하고 소수가 아닌 값을 조합하면 되나 생각을 했었습니다. 하지만 아닌거 같아 좀 찾아보고 조건도 다시 보니 중복도 허용이었고 1 - 9 까지 숫자만 있어서 무조건 YES만 나오는 것을 알게되어 같은 숫자로 2자리 수를 만들었으나 이 부분도 11이 나오.. 2025. 11. 24.