수학을 활용한 풀이다.
간단하게 몫과 나머지를 구하고 n크기 만큼 다 몫으로 채우고 나머지개수만큼 몫+1로 로 채워서 풀이했다.
import java.util.*;
class Solution {
public int[] solution(int n, int s) {
if (n > s)
return new int[]{-1};
int quotient = s / n;
int remainder = s % n;
int[] answer = new int[n];
for (int i = 0; i < n; i++) {
answer[i] = quotient;
if (n - remainder <= i){
answer[i] += 1;
}
}
return answer;
}
}