본문 바로가기

Beakjoon&프로그래머스/Java466

[프로그래머스/Java] 기사단원의 무기 -Codeclass Solution { public int solution(int number, int limit, int power) { int answer = 0; int cnt; for (int i = 1; i 처음에는 1, n까지 모두 검사를 했으나 시간 초과로 틀렸습니다. 그래서 공식을 찾아보니 제곱근을 이용하는 방법을 찾게되었고 다음과 같습니다.1~n까지를 검사할때 예를 들어 n이 24면 1, 2, 3, 4, 6, 8, 12, 24인데 각각 1 * 24, 2 * 12, 3 * 8, 4 * 6으로 묶어서 값을 2개씩  찾는게 가능합니다. 하지만, n이 16처럼 1, 2, 4, 8, 16과 같은 경우 1 * 16, 2 * 8, 4 * 4로 되어서 같은 값.. 2025. 2. 26.
[프로그래머스/Java] 폰켓몬 -Codeimport java.util.Set;import java.util.Arrays;import java.util.stream.Collectors;class Solution { public int solution(int[] nums) { int len = nums.length / 2; Set total = Arrays.stream(nums).boxed() .collect(Collectors.toSet()); return Math.min(total.size(), len); }} 2025. 2. 26.
[프로그래머스/Java] 추억 점수 -Codeimport java.util.*;class Solution { public int[] solution(String[] name, int[] yearning, String[][] photo) { List answer = new ArrayList(); for (String[] line : photo) { List now = List.of(line); int res = 0; for (int i = 0; i 2025. 2. 26.
[프로그래머스/Java] 카드 뭉치 -Codeclass Solution { public String solution(String[] cards1, String[] cards2, String[] goal) { int idx1 = 0, idx2 = 0; boolean flag = true; for (String el : goal) { if (idx1 2025. 2. 26.
[프로그래머스/Java] [1차] 비밀지도 -Codeclass Solution { public String[] solution(int n, int[] arr1, int[] arr2) { String[] answer = new String[n]; String line1; String line2; for (int i = 0; i | 연산을 사용하는 것과 0추가 부분도 %${n}s를 사용하면 쉽게 풀 수 있는데 잊고 있었습니다. 2025. 2. 26.
[프로그래머스/Java] 명예의 전당 (1) -Codeimport java.util.*;class Solution { public int[] solution(int k, int[] score) { List honor = new ArrayList(); List answer = new ArrayList(); for (int p : score) { honor.add(p); Collections.sort(honor); if (honor.size() > k) { honor.remove(0); } answer.add(honor.get(0)); } return answer.stre.. 2025. 2. 26.