Skip to content

Instantly share code, notes, and snippets.

@seiky17
Created February 10, 2025 01:18
Show Gist options
  • Save seiky17/5889097cfa703fd915a53d0507e34c24 to your computer and use it in GitHub Desktop.
Save seiky17/5889097cfa703fd915a53d0507e34c24 to your computer and use it in GitHub Desktop.
import java.util.*;
class Solution {
public int[] solution(int[] arr, int divisor) {
int count = 0;
int number = 0;
for(int i = 0; i < arr.length; i++) {
if(arr[i] % divisor == 0) {
count++;
}
}
if(count == 0) {
int[] answer = {-1};
return answer;
}
int[] answer = new int[count];
for(int i = 0; i < arr.length; i++) {
if(arr[i] % divisor == 0){
answer[number] = arr[i];
number++;
}
}
Arrays.sort(answer);
return answer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment