YJ의 새벽
프로그래머스(0) - n의 배수 고르기 본문
class Solution {
public int[] solution(int n, int[] numlist) {
int[] answer = {};
int count = 0;
int count2 = 0;
for(int i=0; i<numlist.length; i++) {
if(numlist[i] % n == 0) {
count++; // 배수의 갯수 추출
}
}
answer = new int[count]; // 갯수만큼 배열길이 잡아주고
for(int i=0; i<numlist.length; i++) {
if(numlist[i] % n == 0) {
answer[count2] = numlist[i]; // count2 로 배열길이 ++
count2++;
}
}
return answer;
}
}
'코딩테스트연습 > 프로그래머스' 카테고리의 다른 글
프로그래머스(0) - 대문자와 소문자 (0) | 2024.03.13 |
---|---|
프로그래머스(0) - 가위 바위 보 (0) | 2024.03.13 |
프로그래머스(0) - 제곱수 판별하기 (0) | 2024.03.13 |
프로그래머스(0) - 모음 제거 (0) | 2024.03.13 |
프로그래머스(0) - 순서쌍의 개수 (0) | 2024.03.13 |
Comments