1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public long maximumSumOfHeights(List<Integer> maxHeights) { long ans = 0; int n = maxHeights.size(); for (int i = 0; i < n; ++i) { int height = maxHeights.get(i); long t = height; for (int j = i - 1; j >= 0; --j) { height = Math.min(height, maxHeights.get(j)); t += height; } height = maxHeights.get(i); for (int j = i + 1; j < n; ++j) { height = Math.min(height, maxHeights.get(j)); t += height; } ans = Math.max(ans, t); } return ans; } }
|