Skip to content

Commit bdf3754

Browse files
add 1742
1 parent 558e6ba commit bdf3754

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1742|[Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1742.java) ||Easy|Array|
1112
|1736|[Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1736.java) ||Easy|String, Greedy|
1213
|1733|[Minimum Number of People to Teach](https://leetcode.com/problems/minimum-number-of-people-to-teach/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1733.java) ||Medium|Array, Greedy|
1314
|1732|[Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1732.java) ||Easy|Array|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _1742 {
7+
public static class Solution1 {
8+
public int countBalls(int lowLimit, int highLimit) {
9+
Map<Integer, Integer> map = new HashMap<>();
10+
for (int limit = lowLimit, i = 0; limit <= highLimit; limit++, i++) {
11+
int number = 0;
12+
int tmp = limit;
13+
do {
14+
number += tmp % 10;
15+
tmp /= 10;
16+
} while (tmp != 0);
17+
map.put(number, map.getOrDefault(number, 0) + 1);
18+
}
19+
int maxBalls = 0;
20+
for (int c : map.keySet()) {
21+
maxBalls = Math.max(maxBalls, map.get(c));
22+
}
23+
return maxBalls;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)