1. ๋ฌธ์ : https://leetcode.com/problems/container-with-most-water/
๋ง๋ ๋์ด๋ฅผ input์ผ๋ก ๋ฐ์์๋ ์ต๋๋ก ๋ด์์ ์๋ ๋ฌผ์ ์์ ๊ตฌํ๋ ๋ฌธ์
2. ํ์ด
ํฌํฌ์ธํฐ๋ก while๋ฌธ ๋๋ฉด์ ๋ง๋ ์ฎ๊ฒจ๊ฐ๋ฉฐ ์ต๋๊ฐ updateํ๋ฉฐ ํด๊ฒฐ
3. ์ฝ๋
class Solution {
public int maxArea(int[] height) {
int a=0;
int b=height.length-1;
int maxVal = Integer.MIN_VALUE;
while(b != a){
if(height[a]>height[b]){
maxVal = Math.max(maxVal,(b-a)*height[b]);
b--;
}else{
maxVal = Math.max(maxVal,(b-a)*height[a]);
a++;
}
}
return maxVal;
}
}
'๐ป Coding Problems Solving > Two Pointers | Binary Search| LinkedList' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] Linked List Cycle II (0) | 2023.07.10 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ์ฐ์๋ ๋ถ๋ถ ์์ด์ ํฉ (์๋ฐ java) (0) | 2023.05.15 |
[LeetCode] 3Sum (0) | 2023.04.12 |
[BOJ 1806] ๋ถ๋ถํฉ (java) (0) | 2023.04.05 |
[BOJ 14719] ๋น๋ฌผ (0) | 2022.06.26 |
์ต๊ทผ๋๊ธ