def get_max_area(height):
result = 0
for i in range(len(height)):
for j in range(i + 1, len(height)):
temp = 0
w = j - i
if height[i] <= height[j]:
temp = height[i] * w
else:
temp = height[j] * w
if temp >= result:
result = temp
return result
for를 두번 쓸 수 밖에 없었던 점이 아쉽다. for 반복문을 1번으로 끝낼 수 있는 규칙과 로직을 생각해내야 겠다.
def get_max_area(height):
l = 0
r = len(height) -1
area = 0
while l < r:
area = max(area, min(height[l],height[r]) * (r - l))
if height[l] < height[r]:
l += 1
else:
r -= 1
return area
(솔루션 분석 중...)