// https://leetcode.com/problems/beautiful-towers-i/
class Solution {
public:
long long maximumSumOfHeights(vector<int>& h) {
long long ret{};
for (int i = 0, n = h.size(); i < n; ++i) {
long long cur = h[i];
for (int j = i - 1, hc = h[i]; j >= 0; --j) cur += hc = min(hc, h[j]);
for (int j = i + 1, hc = h[i]; j < n; ++j) cur += hc = min(hc, h[j]);
ret = max(ret, cur);
}
return ret;
}
};
beautiful-towers-i
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||