Container With Most Water
来源:互联网 发布:淘宝客如意投推广店铺 编辑:程序博客网 时间:2024/06/05 08:26
问题:
Given n non-negative integers
题意:随意找2个木板构成木桶, 容量最大
关键在于:left和right都向中央移动,每次移动left和Right中间高度较小的( 因为反正都是移动一次,宽度肯定缩小1,这时候只能指望高度增加来增加容量,肯定是替换掉高度较小的,才有可能找到更大的容量。)
#include <iostream>using namespace std;int min(int a, int b){ return a > b ? b : a;}int solution(int a[],int n){ int left = 0, right = n - 1; int vol_max = (right - left)*min(a[right], a[left]); int vol = 0; while (left < right) { if (a[left] < a[right]) left++; else right--; vol = min(a[left], a[right])*(right - left); if (vol_max < vol) vol_max = vol; } return vol_max;}int main(){ int a[5] = { 1,2,3,4,5 }; cout<<solution(a, 5); return 0;}
阅读全文
0 0
- 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
- Container With Most Water
- Container With Most Water
- Container With Most Water
- JavaScript中的作用域
- BZOJ2330(SCOI2011)[糖果]--差分约束系统
- pychart的使用
- android rxjava框架 1.0 操作符介绍
- Python idle 清屏问题解决
- Container With Most Water
- ELK之Filebeat安装与配置及使用
- vs2015智能提示英文改为中文
- linux中线程和进程的详解
- XML 基础详解
- 使用ArrayList集合,对其添加100个不同的元素:
- AE——要素操作(一) 加载已存在shp文件,并进行增删操作
- CentOS 7 下安装 Nginx
- python实现任意位置文件分割