LeetCode题解:Container With Most Water
来源:互联网 发布:高尔夫规则软件 编辑:程序博客网 时间:2024/06/10 06:57
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.
题意:给定n个正整数作为纵坐标,每个数在横坐标上相隔1,求构成的最大矩形
解题思路:最大矩形必然左右矩形纵坐标大于等于中心矩形的纵坐标
代码:
public class Solution { public int maxArea(int[] height) { if(height == null || height.length == 0){ return 0; } int max = 0; int left = 0; int right = height.length - 1; while(left < right){ int temp = Math.min(height[left], height[right]) * (right - left); if(temp > max){ max = temp; } if(height[left] < height[right]){ ++left; }else{ --right; } } return max; }}
0 0
- 【LeetCode】【Python题解】Container with most water
- leetcode题解||Container With Most Water问题
- LeetCode题解: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 题解(72): Container With Most Water
- LeetCode题解——Container With Most Water
- LEETCODE 11 Container With Most Water (JAVA题解)
- LeetCode题解(Week 1):Container With Most Water
- leetcode题解Java | 11. Container With Most Water
- [模拟]LeetCode 11. Container With Most Water 题解
- LeetCode: Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode Container With Most Water
- LeetCode: Container With Most Water
- C++中函数模板的使用
- hdu1443
- 实习小结十三:基于PHP ZF框架的文章管理模块
- iOS9AdaptationTips
- sigsuspend()函数作用详解
- LeetCode题解:Container With Most Water
- spring boot application properties配置详解
- UVA572dfs连通块
- 转 Java内存管理原理及内存区域详解
- 详解 Android 的 Activity 组件
- 【Lua】Lua中的九九乘法表以及字符串拼接
- 生活中的观察者模式
- 【算法入门】广度/宽度优先搜索(BFS)
- Python装饰器与面向切面编程