赞
踩
- package com.henu.lmd;
-
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
-
- public class Demo01_力扣11 {
-
- public static void main(String[] args) {
-
- int[] arr = {1,8,6,2,5,4,8,3,7};
- maxArea(arr);
-
- }
- /*
- * 思想暴力破解,求出每次循环得出的数据,然后添加到list集合中,然后取最大值
- */
- public static void maxArea(int[] arr) {
- int res = 0;
- List<Integer> list = new ArrayList<>();
- for (int i = 0; i < arr.length; i++) {
- for (int j = i+1; j < arr.length; j++) {
- int min = arr[i];
- if (arr[i] > arr[j]) {
- min = arr[j];
- }
- res = min * (j-i);
- list.add(res);
- }
- }
- Collections.sort(list);
- // System.out.println(list);
- System.out.println(list.get(list.size()-1));
- }
-
-
- }
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。