Skip to content

Commit 4d548d2

Browse files
committed
Runtime: 100 ms (Top 96.09%) | Memory: 44.90 MB (Top 25.98%)
1 parent 4884f21 commit 4d548d2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Runtime: 100 ms (Top 96.09%) | Memory: 44.90 MB (Top 25.98%)
2+
3+
class Solution {
4+
private int binarySearch(int[] nums, int target) {
5+
int i = 0;
6+
int j = nums.length;
7+
while(i < j) {
8+
int mid = i + (j - i) / 2;
9+
if(nums[mid] < target) {
10+
i = mid + 1;
11+
} else {
12+
j = mid;
13+
}
14+
}
15+
return i;
16+
}
17+
public int maxDivScore(int[] nums, int[] divisors) {
18+
Arrays.sort(nums);
19+
int max = 0;
20+
int res = divisors[0];
21+
for(int d : divisors) {
22+
int score = 0;
23+
for(int i = binarySearch(nums, d); i < nums.length; ++i) {
24+
if( nums[i] % d == 0) {
25+
++score;
26+
}
27+
}
28+
if(score > max) {
29+
max = score;
30+
res = d;
31+
} else if (score == max) {
32+
res = Math.min(res, d);
33+
}
34+
}
35+
return res;
36+
}
37+
}

0 commit comments

Comments
 (0)