programmers_최고의 집합_java
2023. 2. 28. 11:36ㆍAlgorithm/Programmers
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/12938
class Solution {
public int[] solution(int n, int s) {
int[] answer;
if(n > s){
answer = new int[1];
answer[0] = -1;
}else{
answer = new int[n];
int quotient = s/n;
int remain = s%n;
for(int i = 0; i<n; i++){
answer[i] = quotient;
}
int idx = n-1;
while(remain > 0){
answer[idx--]+=1;
if(idx <0 ) idx = n-1;
remain--;
}
}
return answer;
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_등굣길_java (0) | 2023.02.28 |
---|---|
programmers_야근 지수_java (0) | 2023.02.28 |
programmers_단어 변환_java (0) | 2023.02.27 |
programmers_네트워크_java (0) | 2023.02.27 |
programmers_최솟값 만들기_java (0) | 2023.02.27 |