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
| class Solution { public int maxDivScore(int[] nums, int[] divisors) { Arrays.sort(nums);
int maxScore = -1; int ans = 0; for (int divisor : divisors) { int score = 0; for (int j = nums.length - 1; j >= 0; j--) { if (nums[j] < divisor) { break; } if (nums[j] % divisor == 0) { score++; } }
if (score > maxScore || (score == maxScore && divisor < ans)) { maxScore = score; ans = divisor; } }
return ans; } }
|
References
2644. Find the Maximum Divisibility Score