1,题目
2,思路
首先找到上下左右初始边就开始循环找到上下左右最终边,做面积运算就好了(其中+1是因为下标比实际位置少1)
3,代码
class Solution3195 {public int minimumArea(int[][] grid) {int above = 0;//上int under = 0;//下int left = 0;//左int right = 0;//右boolean b = true;for (int i = 0; i < grid.length; i++) {if (b) {for (int j = 0; j < grid[i].length; j++) {if (grid[i][j] == 1) {above = i;under = i;left = j;right = j;b = false;break;}}} else break;}for (int i = 0; i < grid.length; i++) {for (int j = 0; j < grid[i].length; j++) {if (grid[i][j] == 1) {if (left >= j) {//左left = j;}if (right <= j) {//右right = j;}if (above >= i) {//上above = i;}if (under <= i) {//下under = i;}}}}return (right - left + 1) * (under - above + 1);}
}