Created
February 10, 2025 01:18
-
-
Save seiky17/5889097cfa703fd915a53d0507e34c24 to your computer and use it in GitHub Desktop.
This file contains 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) { | |
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