[LeetCode]11. Container With Most Water
来源:互联网 发布:用vue.js做出来的网页 编辑:程序博客网 时间:2024/06/02 13:10
Problem Description
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container.
[https://leetcode.com/problems/container-with-most-water/]
思路
从两边开始作为杯壁计算容量,然后将矮的一边向中心移动一个位置。
一遍AC~~~~噢噢噢噢噢噢噢噢哦哦哦~
Code
package Q11;public class Solution { public static int maxArea(int[] height) { int ans=0; if(height.length<2) return ans; int right=height.length-1; int left=0; int tmpArea; while(left<right){ tmpArea=(right-left)*Math.min(height[left], height[right]); ans=Math.max(ans, tmpArea); if(height[left]<height[right]){ left++; } else{ right--; } } return ans; }//// public static void main(String[] args) {// int[] a={2,4,3};// System.out.print(maxArea(a));// }}
0 0
- LeetCode 11. Container With Most Water
- [LeetCode]11.Container With Most Water
- LeetCode --- 11. Container With Most Water
- LeetCode 11.Container With Most Water
- [Leetcode] 11. Container With Most Water
- [leetcode] 11.Container With Most Water
- 【leetcode】11. Container With Most Water
- [LeetCode]11. Container With Most Water
- 11. Container With Most Water LeetCode
- leetcode 11. Container With Most Water
- leetcode 11.Container With Most Water
- [LeetCode OJ]11. Container With Most Water
- [leetcode] 11. Container With Most Water
- Leetcode 11. Container With Most Water
- leetcode 11.Container With Most Water
- leetcode 11. Container With Most Water
- LeetCode 11. Container With Most Water
- LeetCode *** 11. Container With Most Water
- android 无线安装apk
- 文法和正规式
- HDU 1548 A strange lift(最短路问题Dijkstra & bfs两种解法)
- 分治算法 Divide and Conquer Algorithm
- install boost on ubuntu
- [LeetCode]11. Container With Most Water
- 高琪-模拟实现JDK中的Arrilist类
- 有限自动机与语法推导树
- [4, Hard, C++] Median of Two Sorted Arrays
- how to install cmake-gui on ubuntu
- 项目技术总结二之SSO单点登录
- 初识三层
- Android中Handler的进阶使用方式
- Hadoop 求平均值 Average