cjql / algorithm

https://cjql.github.io/algorithm/
1 stars 1 forks source link

LeetCode https://leetcode.com/problems/reducing-dishes/ dynamic programming #2

Open cjql opened 4 years ago

cjql commented 4 years ago

C++

Java

Python

def maxSatisfaction(satisfaction):
    res = total = 0
    satisfaction.sort()
    print(satisfaction)
    while satisfaction and satisfaction[-1]+total>0:
        total += satisfaction.pop()
        res += total
        print(satisfaction,total,res)
    return res

a = [-2,5,-1,0,3,-3]
maxSatisfaction(a)
# 5*6+3*5+0-3-2*2-3

C

C

JavaScript

Ruby

Swift

Go

Scala

Kotlin

Rust

PHP