분류 전체보기(74)
-
[백준] 2720. 세탁소 사장 동혁
https://www.acmicpc.net/problem/2720 문제 풀이import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T = Integer.parseInt(br.readLine()); ..
2025.10.10 -
[백준] 10870. 피보나치수 5
https://www.acmicpc.net/problem/10870 풀이1구조가 단순하지만 이미 계산한 fib(n-1)과 fib(n-2)를 다시 계산을 하여 중복 호출이 발생시간 복잡도 : O(2ⁿ) (지수적 증가 → 비효율적)import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;public class Main { static int fib(int n) { if (n == 0) return 0; if (n == 1) return 1; return fib(n - 1) + fib(n - 2); } public static void main(Stri..
2025.10.10 -
[백준] 27433. 팩토리얼2
https://www.acmicpc.net/problem/27433 문제 풀이import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Main { static long factorial(int n) { if (n
2025.10.10 -
[프로그래머스] 12939. 최댓값과 최솟값
https://school.programmers.co.kr/learn/courses/30/lessons/12939 문제 풀이 class Solution { public String solution(String s) { String[] arr = s.split(" "); int min = Integer.parseInt(arr[0]); int max = min; for (int i = 1; i max) max = v; } return min + " " + max; }}
2025.10.10 -
[Leet Code] 4. Median of Two Sorted Arrays
https://leetcode.com/problems/median-of-two-sorted-arrays/?envType=problem-list-v2&envId=array& 문제 설명크기가 각각 m과 n인 두 개의 정렬된 배열 nums1과 nums2가 주어집니다. 두 정렬된 배열의 중앙값(Median)을 반환하세요. 👀 중요: 전체 실행 시간 복잡도는 O(log(m+n)) 이어야 합니다. ⚠️ O(log(m+n)) 의 문제 풀이는 이진 탐색을 이용하여 풀이해야 한다는것을 인지해야 한다! 문제 풀이 1️⃣ 직관적인 첫번째 풀이 방법 : 배열을 합친 후 정렬하기 public double findMedianSortedArrays(int[] nums1, int[] nums2) { ..
2025.10.01 -
120923. 연속된 수의 합
프로그래머스 120923. 연속된 수의 합 문제: 연속된 num개의 정수의 합이 total이 되도록 하는 수들을 찾아 배열로 반환예시 1) num = 3, total = 12출력: [3, 4, 5] → 3 + 4 + 5 = 12예시 2) num = 5, total = 15 출력: [1, 2, 3, 4, 5] → 1 + 2 + 3 + 4 + 5 = 15 해결 방식 1. while 문을 이용한 무차별 대입 (바보 같았다..)⚠️ 문제점무한루프 위험비효율성복잡함public int[] solution(int num, int total) { int start = total / num; // 대략적인 시작점 while (true) { int sum = 0; fo..
2025.09.10