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 8a2b330 commit 1176146Copy full SHA for 1176146
container-with-most-water/delight010.swift
@@ -0,0 +1,22 @@
1
+class Solution {
2
+ func maxArea(_ height: [Int]) -> Int {
3
+ var maxArea = 0
4
+ var startPointIndex = 0
5
+ var endPointIndex = height.count - 1
6
+ while startPointIndex < endPointIndex {
7
+ let minHeight = min(height[startPointIndex], height[endPointIndex])
8
+ let area = minHeight * (endPointIndex - startPointIndex)
9
+ maxArea = max(maxArea, area)
10
+ if height[startPointIndex] < height[endPointIndex] {
11
+ startPointIndex += 1
12
+ } else {
13
+ endPointIndex -= 1
14
+ }
15
16
+ return maxArea
17
18
+}
19
+
20
+// Time Complexity O(N)
21
+// Space Complexity O(1)
22
0 commit comments