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 f7961c5 commit b80c227Copy full SHA for b80c227
container-with-most-water/wogha95.js
@@ -0,0 +1,33 @@
1
+/**
2
+ * TC: O(H)
3
+ * SC: O(1)
4
+ * H: height.length
5
+ */
6
+
7
8
+ * @param {number[]} height
9
+ * @return {number}
10
11
+var maxArea = function (height) {
12
+ let maximumWater = 0;
13
+ let left = 0;
14
+ let right = height.length - 1;
15
16
+ // 1. 투포인터를 이용하여 양끝에서 모입니다.
17
+ while (left < right) {
18
+ // 2. 최대 너비값을 갱신해주고
19
+ const h = Math.min(height[left], height[right]);
20
+ const w = right - left;
21
22
+ maximumWater = Math.max(maximumWater, w * h);
23
24
+ // 3. 왼쪽과 오른쪽 높이 중 더 낮은 쪽의 pointer를 옮깁니다.
25
+ if (height[left] < height[right]) {
26
+ left += 1;
27
+ } else {
28
+ right -= 1;
29
+ }
30
31
32
+ return maximumWater;
33
+};
0 commit comments