본문 바로가기
Beakjoon&프로그래머스/Java

[프로그래머스/Java] 연속된 수의 합

by 현장 2025. 2. 21.

-Code

import 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();
    }
}