Skip to content

Commit d2002f9

Browse files
add 1833
1 parent 6878a2e commit d2002f9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
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+
|1833|[Maximum Ice Cream Bars](https://leetcode.com/problems/maximum-ice-cream-bars/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1833.java) ||Medium|Array, Sort|
1112
|1832|[Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1832.java) ||Easy|String|
1213
|1829|[Maximum XOR for Each Query](https://leetcode.com/problems/maximum-xor-for-each-query/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1829.java) ||Medium|Bit Manipulation|
1314
|1828|[Queries on Number of Points Inside a Circle](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1828.java) ||Medium|Math|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.TreeMap;
4+
5+
public class _1833 {
6+
public static class Solution1 {
7+
public int maxIceCream(int[] costs, int coins) {
8+
TreeMap<Integer, Integer> treeMap = new TreeMap<>();
9+
for (int cost : costs) {
10+
treeMap.put(cost, treeMap.getOrDefault(cost, 0) + 1);
11+
}
12+
int maxIceCream = 0;
13+
for (int cost : treeMap.keySet()) {
14+
if (cost * treeMap.get(cost) <= coins) {
15+
maxIceCream += treeMap.get(cost);
16+
coins -= cost * treeMap.get(cost);
17+
} else {
18+
while (coins > 0 && coins - cost >= 0) {
19+
coins -= cost;
20+
maxIceCream++;
21+
}
22+
break;
23+
}
24+
}
25+
return maxIceCream;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy