Skip to content

Commit 6b98c56

Browse files
committed
1833. 雪糕的最大数量
1 parent f03b198 commit 6b98c56

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.gatsby;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* @ClassName: _1833MaximumIceCreamBars
7+
* @Description: 1833. Maximum Ice Cream Bars
8+
* @author: Gatsby
9+
* @date: 2022/7/29 11:57
10+
*/
11+
12+
public class _1833MaximumIceCreamBars {
13+
public int maxIceCream(int[] costs, int coins) {
14+
Arrays.sort(costs);
15+
int count = 0;
16+
int i = 0;
17+
while (i < costs.length && coins - costs[i] > 0) {
18+
coins -= costs[i++];
19+
count++;
20+
}
21+
return count;
22+
}
23+
}
24+
25+

0 commit comments

Comments
 (0)