From c1c6e19e95e909582f2b1c880e3dea43062c327c Mon Sep 17 00:00:00 2001 From: rl544 <111494264+rl544@users.noreply.github.com> Date: Sat, 17 Dec 2022 21:21:30 +0900 Subject: [PATCH] =?UTF-8?q?uploaded=20at=202022.=2012.=2017.=20=EC=98=A4?= =?UTF-8?q?=ED=9B=84=209:21:28?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../나누어 떨어지는 숫자 배열/solution.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 programmers/나누어 떨어지는 숫자 배열/solution.java diff --git a/programmers/나누어 떨어지는 숫자 배열/solution.java b/programmers/나누어 떨어지는 숫자 배열/solution.java new file mode 100644 index 0000000..f9979f3 --- /dev/null +++ b/programmers/나누어 떨어지는 숫자 배열/solution.java @@ -0,0 +1,17 @@ +// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/12910 + +import java.util.Arrays; +class Solution { + public int[] solution(int[] arr, int divisor) { + int[] answer = new int[arr.length]; + Arrays.sort(arr); + int b = 0; + for(int a : arr){ + if(a%divisor==0){ + answer[b++] = a; + } + } + answer=Arrays.copyOfRange(answer,0,b); + return (answer.length==0)?(new int[] {-1}):answer; + } +} \ No newline at end of file