1. How I Solved
When I checked the all cases, a timeout occurred. So I identified all the possible cases, but adopted a faster method. First of all, it was narrowed inward from both ends of the line, which used the property that the longer the length of the bottom, the larger it becomes. And the higher the height, the larger the area of the rectangle, so the height of the two points was compared to change the position of the smaller points. In this way, the maximum area was found.
2. Code
class Solution:
def maxArea(self, height: List[int]) -> int:
max_area = 0
head, tail = 0, len(height)-1
while head < tail:
area = (tail-head) * min(height[head], height[tail])
max_area = max(max_area, area)
if height[head] > height[tail]:
tail -= 1
else:
head += 1
return max_area
3. Result
Runtime : 728 ms(79.78%), Memory usage : 27.7 MB(22.75%)
(Runtime can be different by a system even if it is a same code.)