-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3195.java
30 lines (29 loc) · 985 Bytes
/
_3195.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.fishercoder.solutions.fourththousand;
public class _3195 {
public static class Solution1 {
/*
* My completely original solution:
* 1. project all 1's to each of the four sides;
* 2. use four variables to denote four corners
*/
public int minimumArea(int[][] grid) {
int m = grid.length;
int n = grid[0].length;
int top = m - 1;
int bottom = 0;
int left = n - 1;
int right = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (grid[i][j] == 1) {
bottom = Math.max(i, bottom);
right = Math.max(j, right);
top = Math.min(top, i);
left = Math.min(j, left);
}
}
}
return (right - left + 1) * (bottom - top + 1);
}
}
}