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 533c70f commit be51247Copy full SHA for be51247
βcontainer-with-most-water/hjeomdev.javaβ
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ public int maxArea(int[] height) {
3
+ // λμ΄ μμλλ‘ μ λ ¬ν΄μ, μ²μλΆν° 2κ°μ© μ‘μμ λλΉλ₯Ό ꡬνλ λ°©λ² => n^2
4
+ // ν΄μ€ μ°Έκ³ ν¨. -> ν¬μΈν° 2κ°λ₯Ό λ¬μ μμΈ‘μμ μμν΄μ μ€κ°μ λ§λ λκΉμ§ μ΅λκ°μ ꡬνλ€
5
+ int s = 0;
6
+ int e = height.length - 1;
7
+ int result = 0;
8
+
9
+ while(s < e) {
10
+ int h = height[s] < height[e] ? height[s] : height[e];
11
+ int w = e - s;
12
+ int cur = h * w;
13
+ if (cur > result) {
14
+ result = cur;
15
+ }
16
17
+ if (height[s] < height[e]) {
18
+ s++;
19
+ } else {
20
+ e--;
21
22
+ // System.out.println(s + " " + e + " " + cur);
23
24
+ return result;
25
26
+}
0 commit comments