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 | import java.util.*; class Solution { public int[] answer(List<Integer> list){ int count =0; if(list.isEmpty()){ int[] answer={-1}; return answer; }else{ int[] answer = new int[list.size()]; for(int i : list){ answer[count] =list.get(count); count++; } Arrays.sort(answer); return answer; } } public int[] solution(int[] arr, int divisor) { List<Integer> list = new ArrayList<>(); for(int i : arr){ if(i%divisor==0){ list.add(i); } } return answer(list); } } | cs |
코테/프로그래머스