프로그래머스 - 연속된 수의 합

youngkyu MIn·2023년 10월 4일

문제링크 - 프로그래머스 - 연속된 수의 합

import java.util.*;

class Solution {
    public int[] solution(int num, int total) {

        List<Integer> list = new ArrayList<>();
        int a = total/num;
        list.add(a);

        for (int i = 1; i <= num/2; i++) {

            list.add(a+i);
            list.add(a-i);

        }

        Collections.sort(list);

        if( num%2 == 0) list.remove(0);

        return list.stream().mapToInt(Integer::intValue).toArray();
    }
}

꼼수..? 인가?

profile
한 줄 소개

0개의 댓글