1788. Maximize the Beauty of the Garden
Содержание
class Solution:
def maximumBeauty(self, flowers: List[int]) -> int:
s = [0] * (len(flowers) + 1)
d = {}
res = -inf
for i, v in enumerate(flowers):
if v in d:
res = max(res, s[i] - s[d[v] + 1] + v * 2)
else:
d[v] = i
s[i + 1] = s[i] + max(v, 0)
return res