• 문제 링크
Container With Most Water - LeetCode
Can you solve this real interview question? Container With Most Water - You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that toget
leetcode.com
• 풀이 코드
public class Solution {
public int maxArea(int[] height) {
int l = 0, r = height.length - 1, max = 0;
while (l < r) {
max = Math.max(max, Math.min(height[l], height[r]) * (r - l));
if (height[l] < height[r]) l++;
else r--;
}
return max;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 13. Roman to Integer - Java (0) | 2026.05.10 |
|---|---|
| [LeetCode] 12. Integer to Roman - Java (0) | 2026.05.09 |
| [LeetCode] 9. Palindrome Number - Java (0) | 2026.05.07 |
| [LeetCode] 3. Longest Substring Without Repeating Characters - Java (0) | 2026.05.06 |
| [LeetCode] 2. Add Two Numbers - Java (0) | 2026.05.05 |
댓글