프로그래머스 나누어 떨어지는 숫자 배열 - java


프로그래머스 나누어 떨어지는 숫자 배열 - java

import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { int[] answer = {}; ArrayList<Integer> list = new ArrayList<>(); for (int i = 0 ; i < arr.length ; i++) { if (arr[i]%divisor == 0) { list.add(arr[i]); } } if (list.size()==0) { return new int[] {-1}; } Integer[] buff = list.toArray(new Integer[0]); Arrays.sort(buff); answer = Arrays.stream(buff).mapToInt(Integer::intValue).toArray(); return answer; } } 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/...



원문링크 : 프로그래머스 나누어 떨어지는 숫자 배열 - java