We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4938349 commit 322bffdCopy full SHA for 322bffd
container-with-most-water/i-mprovising.py
@@ -0,0 +1,22 @@
1
+"""
2
+Time complexity O(n)
3
+Space complexity O(1)
4
+
5
+Two pointer
6
7
8
+class Solution:
9
+ def maxArea(self, height: List[int]) -> int:
10
+ s, e = 0, len(height) - 1
11
+ area = 0 # max area
12
+ while s < e:
13
+ h = min(height[s], height[e])
14
+ tmp = h * (e - s) # area at current iteration
15
+ area = max(area, tmp)
16
+ # move pointer
17
+ if height[s] < height[e]:
18
+ s += 1
19
+ else:
20
+ e -= 1
21
22
+ return area
0 commit comments