Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.
A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
입출력 예시:
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
public class ContainerWithMostWater {
public static void main(String[] args) {
int[] test = new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}; // 49
System.out.println(maxArea(test));
}
private static int maxArea(int[] height) {
int i = 0;
int j = height.length - 1;
int ans = 0;
while(i != j) {
int area = (j - i) * Math.min(height[i], height[j]);
if(area >= ans) {
ans = area;
}
if(height[i]>height[j]) {
j--;
} else {
i++;
}
} return ans;
}
}
i
라는 수와 맨끝에서 시작하는 j
라는 수를 만들어준다. j-i
가 된다.ans
라는 값을 계속 갱신해줌으로써 최대넓이를 찾아낸다.