Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7951b7d

Browse files
committed
1833. Maximum Ice Cream Bars
1 parent 5d8cb6e commit 7951b7d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎18/1833-Maximum_Ice_Cream_Bars.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
3+
fun maxIceCream(costs: IntArray, coins: Int): Int {
4+
var current = 0
5+
var coinsLeft = coins
6+
7+
costs.sort()
8+
9+
while (coinsLeft > 0 && current < costs.size && costs[current] <= coinsLeft) {
10+
coinsLeft -= costs[current]
11+
current++
12+
}
13+
14+
return current
15+
}
16+
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /