Skip to content

Commit 030fcfc

Browse files
add 2644
1 parent d6a0f5c commit 030fcfc

File tree

3 files changed

+59
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+59
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2656.java) | | Easy |
2525
| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2652.java) | | Easy |
2626
| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2651.java) | | Easy |
27+
| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2644.java) | | Easy |
2728
| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2643.java) | | Easy |
2829
| 2641 | [Cousins in Binary Tree II](https://leetcode.com/problems/cousins-in-binary-tree-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2641.java) | | Medium |Tree, BFS, HashTable
2930
| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2605.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2644 {
4+
public static class Solution1 {
5+
public int maxDivScore(int[] nums, int[] divisors) {
6+
int[][] scores = new int[divisors.length][2];
7+
for (int i = 0; i < divisors.length; i++) {
8+
int score = 0;
9+
for (int j = 0; j < nums.length; j++) {
10+
if (nums[j] % divisors[i] == 0) {
11+
score++;
12+
}
13+
}
14+
scores[i][0] = score;
15+
scores[i][1] = divisors[i];
16+
}
17+
int maxScore = -1;
18+
for (int i = 0; i < divisors.length; i++) {
19+
maxScore = Math.max(maxScore, scores[i][0]);
20+
}
21+
int ans = Integer.MAX_VALUE;
22+
for (int i = 0; i < divisors.length; i++) {
23+
if (maxScore == scores[i][0]) {
24+
if (ans > scores[i][1]) {
25+
ans = scores[i][1];
26+
}
27+
} else if (maxScore < scores[i][0]) {
28+
maxScore = scores[i][0];
29+
ans = scores[i][1];
30+
}
31+
}
32+
return ans;
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2644;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2644Test {
10+
private static _2644.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2644.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.maxDivScore(new int[]{2, 9, 15, 50}, new int[]{5, 3, 7, 2}));
20+
}
21+
22+
23+
}

0 commit comments

Comments
 (0)