CODE 120: Container With Most Water
来源:互联网 发布:java中的sleep 编辑:程序博客网 时间:2024/05/17 06:48
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.
public int maxArea(int[] height) {// Start typing your Java solution below// DO NOT write main() functionif (null == height || height.length <= 0) {return 0;}int max = Integer.MIN_VALUE;for (int i = 0; i < height.length; i++) {for (int j = 0; j < i; j++) {if (height[j] >= height[i]) {int tmp = (i - j) * height[i];if (tmp > max) {max = tmp;}break;}}for (int j = height.length - 1; j > i; j--) {if (height[j] >= height[i]) {int tmp = (j - i) * height[i];if (tmp > max) {max = tmp;}break;}}}return max;}
- CODE 120: Container With Most Water
- [leet code] Container With Most Water
- Leet Code 11 Container With Most Water
- 【LEET-CODE】11. Container With Most Water
- Container With Most Water
- Container with most water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- oracle查询结果中wmsys.wm_concat组合一列多行结果,以及每行中某些列的组合结果
- php学习之数组(2)直接键创建数组以及list each的用法
- ios7新特性--19
- Hibernate优化(四) 之缓存机制详解
- 回文数
- CODE 120: Container With Most Water
- 《写给大家看的c语言书》中所用部分函数解析
- 嵌入式系统 Boot Loader 技术内幕(很不错到,值得推荐)
- hdu 1162
- 关于java容器的作为数据内存的情况
- 解决问题的一点体会
- android列表下拉刷新
- excel操作技巧之,相对引用和绝对引用($)
- 黑马程序员--银行调度系统