Skip to content

Commit 65e2fba

Browse files
authored
Refactored Container With Most Water.java
1 parent d5dda98 commit 65e2fba

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Medium/Container With Most Water.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
class Solution {
22
public int maxArea(int[] height) {
3+
int maxWater = 0;
34
int start = 0;
45
int end = height.length - 1;
5-
int maxArea = 0;
66
while (start < end) {
77
int minHeight = Math.min(height[start], height[end]);
8-
int dist = end - start;
9-
maxArea = Math.max(maxArea, minHeight * dist);
8+
maxWater = Math.max(maxWater, minHeight * (end - start));
109
if (height[start] > height[end]) {
1110
end--;
12-
}
13-
else {
11+
} else {
1412
start++;
1513
}
1614
}
17-
return maxArea;
15+
return maxWater;
1816
}
1917
}

0 commit comments

Comments
 (0)