File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ import java .io .*;
3
+
4
+ class Main {
5
+
6
+ public static int MaximalSquare (String [] strArr ) {
7
+
8
+ char [][] arr1 = new char [strArr .length ][strArr [0 ].length ()];
9
+
10
+ for (int i =0 ; i <strArr .length ; i ++){
11
+ for (int j =0 ; j <strArr [0 ].length () ; j ++){
12
+
13
+ arr1 [i ][j ]=strArr [i ].charAt (j );
14
+
15
+ }
16
+ }
17
+
18
+ int x = arr1 .length +1 ;
19
+ int y = arr1 [0 ].length +1 ;
20
+
21
+ int [][] arr2 = new int [x ][y ];
22
+
23
+ int max =0 ;
24
+
25
+ for (int i = 1 ; i <x ; i ++){
26
+ for (int j =1 ; j <y ; j ++){
27
+
28
+ if (arr1 [i -1 ][j -1 ]=='1' ){
29
+
30
+ arr2 [i ][j ]= Math .min (arr2 [i -1 ][j -1 ],Math .min (arr2 [i -1 ][j ],arr2 [i ][j -1 ]))+1 ;
31
+
32
+ if (arr2 [i ][j ]>max ){
33
+
34
+ max =arr2 [i ][j ];
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ return max *max ;
41
+ }
42
+
43
+ public static void main (String [] args ) {
44
+ // keep this function call here
45
+ Scanner s = new Scanner (System .in );
46
+ System .out .print (MaximalSquare (s .nextLine ()));
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments