C++ HackerRank|Largest Rectangle

来源:互联网 发布:海岛大亨5知乎 编辑:程序博客网 时间:2024/06/06 05:35

  1. Dashboard 
  2.  Data Structures 
  3.  Stacks 
  4.  Largest Rectangle
    1. #include <vector>#include <iostream>using namespace std;int main(int argc, char const *argv[]){    int n;    cin >> n;    vector<int> height(n);    for (int i = 0; i < n; ++ i)    {        cin >> height[i];    }    int prev, next;    long long maxi = 0, temp;    for (int i = 0; i < n; ++ i)    {        temp = height[i];        prev = i - 1;        next = i + 1;        while (prev >= 0 && height[prev] >= height[i])        {            temp += height[i];            -- prev;        }        while (next < n && height[next] >= height[i])        {            temp += height[i];            ++ next;        }        maxi = temp > maxi ? temp : maxi;    }    cout << maxi << endl;    return 0;}


0 0
原创粉丝点击