在一个牧场中,有n个牛舍,每个牛舍的占地面积都不同。每个牛舍都与相邻的牛舍紧密相连,每个牛舍的宽度都为1。每个牛舍的长度都不同,记录在数组areas中。 现在需要在这些牛舍中选择一些连续的牛舍盖棚,棚是长方形的,为了节省成本,它能照顾到同样的宽度,但是只能照顾到较短的长度,求棚能覆盖的到的最大面积。
示例1
输入
[5,4,3,2,1]
输出
9
说明
前三个牛舍拼起来
示例2
输入
[2,4]
输出
4
备注:
1 0
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ public int maxArea (int[] areas) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型vector * @return int整型 */ int maxArea(vector
& areas) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param areas int整型一维数组 # @return int整型 # class Solution: def maxArea(self , areas ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ public int maxArea (List
areas) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ function maxArea( areas ) { // write code here } module.exports = { maxArea : maxArea };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param areas int整型一维数组 # @return int整型 # class Solution: def maxArea(self , areas: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ func maxArea( areas []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @param areasLen int areas数组长度 * @return int整型 */ int maxArea(int* areas, int areasLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param areas int整型一维数组 # @return int整型 # class Solution def maxArea(areas) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ def maxArea(areas: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ fun maxArea(areas: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ public int maxArea (int[] areas) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ export function maxArea(areas: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ func maxArea ( _ areas: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param areas int整型一维数组 * @return int整型 */ pub fn maxArea(&self, areas: Vec
) -> i32 { // write code here } }
[5,4,3,2,1]
9
[2,4]
4