LeetCode #84
来源:互联网 发布:java小项目开发实例 编辑:程序博客网 时间:2024/04/24 09:10
题目描述:
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]
.
The largest rectangle is shown in the shaded area, which has area = 10
unit.
For example,
Given heights = [2,1,5,6,2,3]
,
return 10
.
class Solution {public: int largestRectangleArea(vector<int>& heights) { int result=0; for(int i=0;i<heights.size();i++) { if((i<(heights.size()-1)&&heights[i+1]<heights[i])||(i==heights.size()-1)) { int min_height=heights[i]; int min_area=heights[i]; for(int j=i;j>=0;j--) { min_height=min(min_height,heights[j]); min_area=min_height*(i-j+1); result=max(result,min_area); } } } return result; }};
阅读全文
0 0
- LeetCode 84
- LeetCode #84
- leetcode 84: Word Ladder
- LeetCode 84 Text Justification
- Leetcode no. 84
- *leetcode #84 in cpp
- leetCode练习(84)
- [Leetcode] 71, 32, 84
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- css 常见页面布局之圣杯布局(margin负值法)
- jsp字符编码过滤器的实现
- pygame.Color
- 树莓派编译内核(编译模块)
- CSS3盒子阴影属性
- LeetCode #84
- cocos creator(十一)http协议
- Qt操作MySql数据库进行增删改查
- Codeforces Round #381 (Div. 2) E. Alyona and towers 差分+ 线段树并
- 整数判重、大整数Hash
- 二叉树的创建、遍历
- 实战 SSH 端口转发
- 用户行为采集从想法到实现
- JSP小整理(二)