Skip to content

Commit 5b5aef4

Browse files
author
Tony
committed
1402.reducing-dishes.py
1 parent b215bce commit 5b5aef4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

1402.reducing-dishes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# @lc app=leetcode id=1402 lang=python3
3+
#
4+
# [1402] Reducing Dishes
5+
#
6+
7+
# @lc code=start
8+
from typing import List
9+
10+
class Solution:
11+
def maxSatisfaction(self, satisfaction: List[int]) -> int:
12+
satisfaction.sort()
13+
best_ltc = 0
14+
ltc = 0
15+
s = 0
16+
for i in reversed(range(len(satisfaction))):
17+
s += satisfaction[i]
18+
ltc += s
19+
if ltc < best_ltc:
20+
break
21+
best_ltc = ltc
22+
return best_ltc
23+
# @lc code=end
24+
25+
from test_utils import run_test
26+
27+
method = Solution().maxSatisfaction
28+
29+
run_test(method, [[-1,-8,0,5,-9]], 14)
30+
run_test(method, [[4,3,2]], 20)
31+
run_test(method, [[-1,-4,-5]], 0)

0 commit comments

Comments
 (0)