程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[leetcode question brushing Python] 11 Container with the most water

編輯:Python

1 subject

Given a length of n Array of integers for height . Yes n Vertical line , The first i The two ends of the line are (i, 0) and (i, height[i]) .
Find two of them , Make them x A container of shafts can hold the most water .
Return the maximum amount of water that the container can store .

2 analysis

3 python Realization

def maxArea(self, height: List[int]) -> int:
i,j,res = 0,len(height)-1,0
while i<j:
if height[i]<height[j]:
res = max(res,height[i]*(j-i))
i +=1
else:
res = max(res,height[j]*(j-i))
j -=1
return res

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved