전체 글2868 [프로그래머스/Java] 연속된 수의 합 -Codeimport java.util.stream.IntStream;class Solution { public int[] solution(int num, int total) { int start = num % 2 == 0 ? total / num - (num / 2) + 1 : total / num - (num / 2); int end = total / num + (num / 2); return IntStream.rangeClosed(start, end).toArray(); }} 2025. 2. 21. [프로그래머스/Java] 다항식 더하기 -Codeclass Solution { public String solution(String polynomial) { int x_val = 0, num_val = 0; for (String s : polynomial.split(" ")) { if (s.equals("+")) continue; if (s.charAt(s.length() - 1) == 'x') { x_val += s.length() != 1 ? Integer.parseInt(s.substring(0, s.length() - 1)) : 1; } e.. 2025. 2. 21. [프로그래머스/Java] 특이한 정렬 -Codeimport java.util.Arrays;import java.util.Comparator;class Solution { public int[] solution(int[] numlist, int n) { return Arrays.stream(numlist) .boxed() .sorted(Comparator.comparing((Integer num) -> Math.abs(num - n)) .thenComparing((a, b) -> Integer.compare(b, a))) .mapToInt(Integer::intValue) .. 2025. 2. 21. [백준/파이썬] 31394번 Scholarship -Codedef Scholarship(list) : avg = sum(list) / len(list) if avg == 5: return "Named" if avg >= 4.5 and 3 not in list: return "High" if 3 in list: return "None" return "Common"scores = [int(input()) for _ in range(int(input()))]print(Scholarship(scores)) 2025. 2. 21. [프로그래머스/Java] 유한소수 판별하기 -Codeclass Solution { public int solution(int a, int b) { int n = b / getGcd(a, b); while (n != 1) { if (n % 5 == 0) n /= 5; else if (n % 2 == 0) n /= 2; else return 2; } return 1; } public static int getGcd(int n1, int n2) { return n1 % n2 == 0 ? n2 : getGcd(n2, n1 % n2); }}while문 종료 조건을 잘 못찾아서 힌트등을 보고 해결했습니다. 2025. 2. 21. [프로그래머스/Java] 등수 매기기 -Codeimport java.util.*;import java.util.stream.Collectors;class Solution { public int[] solution(int[][] score) { int[] answer = new int[score.length]; List sorted_list = Arrays.stream(score) .map(arr -> (arr[0] + arr[1])) .mapToInt(Integer::intValue) .boxed().collect(Collectors.toList()); sorted_list.sort(Comparator.reverseOr.. 2025. 2. 21. 이전 1 2 3 4 5 6 7 ··· 478 다음