contain the most water


Submit solution

Points: 50 (partial)
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Java 19, Java 8

本題接受Java8、Java19,同學可自行選取合適的版本進行作答

題目說明

給定一長度為n,代表高度的陣列,尋找兩高度間能乘載的最多水量,並輸出出來

注意 不用考慮傾斜狀況
輸入限制 正整數

輸入

陣列長度、高度值

輸出

能乘載的最多水量

測試資料0 輸入

9 1 8 6 2 5 4 8 3 7

測試資料0 輸出

49
解釋

陣列中的高度值為y軸,其中第二項的8與最後項的7可乘載最多的水量(7(高度) * 7(x軸寬) = 49),乘載水量可無視中間的高度值

測試資料1 輸入

2 1 1

測試資料1 輸出

1

Comments

There are no comments at the moment.