当前位置:网站首页>Composition maximum area
Composition maximum area
2022-06-09 12:05:00 【N. LAWLIET】
problem
ask : give n Nonnegative integers , Each integer represents a coordinate point (i,ai) Draw n Bar vertical line , Line i There are two endpoints (i,ai) and (i,0) Their starting points are contained in x On the shaft , Excuse me, n How can a line contain the most water .( Select any two poles to store the most water )
Example
A little
thought
Find the maximum area between two rods , Double pointer method . Find the maximum area , Minimum value of height selector lever .
Code
public class Code02_ContainerWithMostWater {
public static int maxArea(int[] h) {
int r = h.length;
int l =0;
int max = 0;
while(l<r) {
max = Math.max(max, Math.min(h[l], h[r])*(r-l));
if(h[l]<h[r]) l++;
else {
r--;
}
}
return max;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = Integer.parseInt(scanner.nextLine());
int[] h = new int[N];
for(int i = 0;i<N ;i++) {
h[i] = scanner.nextInt();
}
int res = maxArea(h);
System.out.println(res);
}
}
边栏推荐
- UDP可靠性实践
- Win10 20H2正式发布,对比旧版&新功能一览
- 06 | 中台落地第一步:企业战略分解及现状调研(Discovery)
- IPv6 address assignment
- 1.<tag-回溯和组合及其剪枝>lt.77.组合 +剪枝 dyh
- Learning notes of segmentation, paging, page table and quick table
- Iphone5s display disabled solution
- 【管理知多少】中文“其他”、英文“OTHER”、日文“その他”.......
- SIGIR 2022 | CMI:结合对比学习和多兴趣挖掘的微视频推荐
- [reprint] understand G1 garbage collector
猜你喜欢

10. < tag binary tree and BST foundation > lt.700 Search in binary search tree + lt.98 Validate binary search tree + lt.530 Minimum absolute difference of binary search tree (the same as lt.783)

8K resolution 7680*4320

7.<tag-回溯和子集问题>lt.70.子集 + lt.90.子集 II

【管理知多少】中文“其他”、英文“OTHER”、日文“その他”.......

PMP project management knowledge system

08 | middle stage landing step 3: middle stage planning and design

03 | 中台定义:当我们谈中台时到底在谈些什么?

7. remove elements

No remote desktop license server can provide licenses

06 | 中台落地第一步:企业战略分解及现状调研(Discovery)
随机推荐
8. < tag backtracking and full arrangement > lt.46 Full Permutation + lt.47 Full arrangement II
Simple use of GDB
09 | 中台落地第四步:中台的建设与接入(Delivery)
7. < tag backtracking and subset problem > lt.70 Subset + lt.90 Subset II
6.<tag-回溯和切割问题>lt.131.分割回文串
No remote desktop license server can provide licenses
Answers to six basic questions of security assessment for commercial password applications
[data center stage] 00 opening words data center stage, is it a trap? Or the golden key?
MySQL SQL语句优化
H3C certified cloud computing Engineer
系统集成项目管理工程师考试说明
08 | 中台落地第三步:中台的规划与设计(Design)
Prompt credssp encryption database correction when windows is remote
组成最大面积
5. bracket generation
爱可可AI前沿推介(6.9)
H3C Certified Network Engineer
Suggested collection: concept, classification, value of data standards and analysis of six implementation steps
1. < tag backtracking, combination and pruning > lt.77 Combination + pruning dyh
spark 写入doris太慢方案解决