class Solution {
public int[] solution(int num, int total) {
int[] answer = new int[num];
int nSum = num *(1+num)/2;
int start = (total - nSum)/num;
for(int i =1; i<num+1; i++){
answer[i-1] = i+start;
}
return answer;
}
}
class Solution {
fun solution(num: Int, total: Int): IntArray {
var answer: IntArray = IntArray(num)
var nSum: Int = num *(1+num) /2
var start : Int = (total - nSum)/num
for (i in 1..num){
answer[i-1] = i+start;
}
return answer
}
}
고수의 실력 코딩
class Solution {
fun solution(num: Int, total: Int): IntArray =
(total / num - (num - 1) / 2).let { t -> IntArray(num) { index -> index + t } }
}