Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 플러터
- 시큐리티
- Spring Security
- backjoon
- Java
- 리눅스
- 스프링 부트 쇼핑몰 프로젝트 with JPA
- postgresql
- javascript
- 데이터베이스
- 스프링
- 자료구조
- 파이썬
- springboot
- 자바
- spring
- 스프링부트
- 백준
- JPA
- 프로그래머스
- Flutter
- DB
- 데이터
- python
- baekjoon
- CS지식
- CS
- 네트워크
- 자바스크립트
- Oracle
Archives
- Today
- Total
Jin's Dev Story
[프로그래머스 Lv0.] 120905번 n의 배수 고르기 (JAVA) 본문
1. 문제
문제 설명
정수 n과 정수 배열 numlist가 매개변수로 주어질 때, numlist에서 n의 배수가 아닌 수들을 제거한 배열을 return하도록 solution 함수를 완성해주세요.
제한사항
- 1 ≤ n ≤ 10,000
- 1 ≤ numlist의 크기 ≤ 100
- 1 ≤ numlist의 원소 ≤ 100,000
입출력 예
n | numlist | result |
3 | [4, 5, 6, 7, 8, 9, 10, 11, 12] | [6, 9, 12] |
5 | [1, 9, 3, 10, 13, 5] | [10, 5] |
12 | [2, 100, 120, 600, 12, 12] | [120, 600, 12, 12] |
2. 풀이과정
class Solution {
public int[] solution(int n, int[] numlist) {
int[] arry = new int[numlist.length];
int count = 0;
for(int i = 0; i<numlist.length; i++){
if( numlist[i]%n == 0){
arry[count] = numlist[i];
count++;
}
}
int[] answer = new int[count];
for(int i = 0; i<count; i++){
answer[i] = arry[i];
}
return answer;
}
}
'Coding Test > 프로그래머스[JAVA]' 카테고리의 다른 글
[프로그래머스 Lv0.] 181845번 문자열로 변환 (JAVA) (0) | 2023.07.20 |
---|---|
[프로그래머스 Lv0.] 120845번 주사위의 개수 (JAVA) (0) | 2023.07.20 |
[프로그래머스 Lv0.] 120892번 암호 해독 (JAVA) (0) | 2023.07.20 |
[프로그래머스 Lv0.] 120837번 개미 군단 (JAVA) (0) | 2023.07.20 |
[프로그래머스 Lv0.] 181910번 문자열의 뒤의 n글자 (JAVA) (0) | 2023.07.20 |