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 4c4c415 commit ad4b1cbCopy full SHA for ad4b1cb
1 file changed
โcontainer-with-most-water/gcount85.pyโ
@@ -0,0 +1,24 @@
1
+"""
2
+# Approach
3
+ํฌํฌ์ธํฐ๋ก ์ ๋์์ ๋ฌผ์ ์์ ๊ณ์ฐํด๋๊ฐ๋๋ค.
4
+๋ ๋ฎ์ height์ธ ์ชฝ์ ํฌ์ธํฐ๋ฅผ ์ค์ฌ๋๊ฐ๋๋ฐ, ๋์ด๊ฐ ๊ฐ์ ๊ฒฝ์ฐ์๋ ์์ชฝ ๋ชจ๋ ํฌ์ธํฐ๋ฅผ ์์ง์ ๋๋ค.
5
+
6
+# Complexity
7
+height์ ๊ธธ์ด๊ฐ N์ผ ๋
8
+- Time complexity: O(N)
9
+- Space complexity: O(1)
10
11
12
13
+class Solution:
14
+ def maxArea(self, height: list[int]) -> int:
15
+ n = len(height)
16
+ left, right = 0, n - 1
17
+ best = 0
18
+ while left < right:
19
+ best = max(best, (right - left) * min(height[left], height[right]))
20
+ if height[left] > height[right]:
21
+ right -= 1
22
+ else:
23
+ left += 1
24
+ return best
0 commit comments