11. Container With Most Water
来源:互联网 发布:淘宝买刺刀 编辑:程序博客网 时间:2024/06/04 19:51
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 linei 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 class Solution { public int maxArea(int[] height) { int left = 0;int right = height.length-1;int max = 0,temp = 0;while(left<right) {if(height[left] > height[right]){temp = (right-left) * height[right];right--;}else{temp = (right-left) * height[left];left++;}max = max > temp ? max :temp;}return max; }}//从两端开始遍历数组,每次计算结果,那边数值高,则缩进,以此寻找最小的
//从两端开始遍历数组,每次计算结果,那边数值高,则缩进,以此寻找最小的
0 0
- 11.Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11.Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- lightoj 1033 - Generating Palindromes(区间dp)
- 链表的反转
- Android开发:最详细的 Toolbar 开发实践总结
- IOS CGAffineTransform 用于视图平移,缩放,旋转
- 读书笔记--《高效能程序员的修炼》
- 11. Container With Most Water
- MonoBehaviour lifecycle and leaks explained
- 开源网络准入系统(open source Network Access Control system)
- poj-2388-Who's in the Middle
- Android 入门ListView 的基本使用,BaseAdapter的编写
- 新内核版本ioctl的变化 _IO, _IOR, _IOW, _IOWR 幻数的理解
- 负载均衡与集群之apache+tomcat
- git git bash git shell的区别
- myeclipse2015逆向工程错误An internal error occurred during: "Generating Artifacts". java.lang.NullPointerE