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 426e28c commit 70f36edCopy full SHA for 70f36ed
container-with-most-water/HoonDongKang.ts
@@ -0,0 +1,31 @@
1
+/**
2
+ * [Problem]: [11] Container With Most Water
3
+ * (https://leetcode.com/problems/container-with-most-water/description/)
4
+ */
5
+function maxArea(height: number[]): number {
6
+ //시간복잡도 O(n)
7
+ //공간복잡도 O(1)
8
+ function twoPointerFunc(height: number[]): number {
9
+ let left = 0;
10
+ let right = height.length - 1;
11
+ let result = 0;
12
+
13
+ while (left < right) {
14
+ const length = Math.min(height[left], height[right]);
15
+ console.log(length);
16
+ const area = (right - left) * length;
17
18
+ result = Math.max(area, result);
19
20
+ if (height[left] < height[right]) {
21
+ left++;
22
+ } else {
23
+ right--;
24
+ }
25
26
27
+ return result;
28
29
30
+ return twoPointerFunc(height);
31
+}
0 commit comments