直方图内最大矩形
题解
讨论
查看他人的提交
题号:NC229978
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
给定一个数组heights,长度为n,height[i]是在第i点的高度,那么
height[i]表示的直方图,能够形成的最大矩形是多少?
1.每个
直方图
宽度都为1
2.
直方图
都是相邻的
3.如果不能形成矩形,返回0即可
4.保证返回的结果不会超过2
31
-1
数据范围:
如输入[3,4,7,8,1,2],那么如下:
示例1
输入
复制
[3,4,7,8,1,2]
[3,4,7,8,1,2]
返回值
复制
14
14
示例2
输入
复制
[1,7,3,2,4,5,8,2,7]
[1,7,3,2,4,5,8,2,7]
返回值
复制
16
16
直方图内最大矩形
返回全部题目
列表加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ public int largestRectangleArea (int[] heights) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型vector * @return int整型 */ int largestRectangleArea(vector
& heights) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param heights int整型一维数组 # @return int整型 # class Solution: def largestRectangleArea(self , heights ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ public int largestRectangleArea (List
heights) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ function largestRectangleArea( heights ) { // write code here } module.exports = { largestRectangleArea : largestRectangleArea };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param heights int整型一维数组 # @return int整型 # class Solution: def largestRectangleArea(self , heights: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ func largestRectangleArea( heights []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @param heightsLen int heights数组长度 * @return int整型 */ int largestRectangleArea(int* heights, int heightsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param heights int整型一维数组 # @return int整型 # class Solution def largestRectangleArea(heights) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ def largestRectangleArea(heights: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ fun largestRectangleArea(heights: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ public int largestRectangleArea (int[] heights) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ export function largestRectangleArea(heights: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ func largestRectangleArea ( _ heights: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ pub fn largestRectangleArea(&self, heights: Vec
) -> i32 { // write code here } }
[3,4,7,8,1,2]
14
[1,7,3,2,4,5,8,2,7]
16