zoukankan      html  css  js  c++  java
  • Container With Most Water

        题意是有个高度数组,就相当于隔板的高度,求数组中任意两隔板间盛水的最大量。隔板间的距离与较低隔板的高度乘积即为盛水的容量。

    int maxArea(vector<int> &height) 
    {
        int capability = 0;
        size_t left = 0, right = height.size() - 1;
        
        while (left < right)
        {
            const int water = 
                min(height[left], height[right]) * (right - left);
            
            if (water > capability) capability = water;
            
            if (height[left] < height[right])
            {
                ++left;
            }
            else
            {
                --right;
            }
        }
        
        return capability;
    }
  • 相关阅读:
    IE11浏览器:请不要再叫我IE,谢谢
    Hadoop HA高可用搭建流程
    YARN
    MapReduce
    HDFS
    shell
    shell总结
    linux总结
    maven+log4j
    Spring
  • 原文地址:https://www.cnblogs.com/codingmylife/p/2671548.html
Copyright © 2011-2022 走看看