Skip to content

Commit a5e97f3

Browse files
authored
Create maximum-bags-with-full-capacity-of-rocks.py
1 parent e966a67 commit a5e97f3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Time: O(nlogn)
2+
# Space: O(1)
3+
4+
# sort, greedy
5+
class Solution(object):
6+
def maximumBags(self, capacity, rocks, additionalRocks):
7+
"""
8+
:type capacity: List[int]
9+
:type rocks: List[int]
10+
:type additionalRocks: int
11+
:rtype: int
12+
"""
13+
for i in xrange(len(capacity)):
14+
capacity[i] -= rocks[i]
15+
capacity.sort()
16+
result = 0
17+
for c in capacity:
18+
cnt = min(c, additionalRocks)
19+
additionalRocks -= cnt
20+
c -= cnt
21+
if not c:
22+
result += 1
23+
return result

0 commit comments

Comments
 (0)