Skip to content

Commit 286be52

Browse files
authored
Create reducing-dishes.py
1 parent 76a1653 commit 286be52

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/reducing-dishes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(nlogn)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxSatisfaction(self, satisfaction):
6+
"""
7+
:type satisfaction: List[int]
8+
:rtype: int
9+
"""
10+
satisfaction.sort(reverse=True)
11+
result, curr = 0, 0
12+
for x in satisfaction:
13+
curr += x
14+
if curr <= 0:
15+
break
16+
result += curr
17+
return result

0 commit comments

Comments
 (0)