Created
July 7, 2020 14:31
-
-
Save dalcon10028/2c216e1753e9f281474a60f4df7a62c5 to your computer and use it in GitHub Desktop.
프로그래머스 코딩테스트 연습 Level1 - 나누어 떨어지는 숫자 배열 [ Java ]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Solution { | |
public int[] solution(int[] arr, int divisor) { | |
LinkedList<Integer> list = new LinkedList<>(); | |
Arrays.sort(arr); | |
for (int i : arr) | |
if(i%divisor==0) | |
list.add(i); | |
if(list.isEmpty()) list.add(-1); | |
return list.stream().mapToInt(i->i).toArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment