My Solution (BF)
1 | class Solution { |
Remarks:
- use
.length
but NOT.size()
for an array - area in decided by the
min
of two heights - TC: $O(n!)$ too big!!
Double Pointer
1 | class Solution { |
Remarks:
- TC: $O(n)$
- Why it works? if we move the longer line, the height is still the smaller one, while the base width is smaller. Thus, no matter how we move the longer line, the size always decreases. Hence, we move the shorter line.