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
31
32
33
34
35
36
37
38
39
40
41
42
43
| class TryHelloWorld
{
public int findLargestSquare(char [][]board)
{
int max=0;
int min=0;
for(int i=0;i<board.length;i++) {
for(int j=0;j<board[0].length;j++) {
if(board[i][j]=='O')
board[i][j]=1;
else
board[i][j]=0;
}
}
for(int i=0;i<board.length-1;i++) {
for(int j=0;j<board[0].length-1;j++) {
if(board[i][j]==0||board[i][j+1]==0||board[i+1][j]==0||board[i+1][j+1]==0)
continue;
else{
min = board[i][j] < board[i][j+1] ? (board[i][j] < board[i+1][j] ? board[i][j] : board[i+1][j]) : (board[i][j+1] < board[i+1][j] ? board[i][j+1] : board[i+1][j]);
board[i+1][j+1] = (char) (min+1);
if(board[i+1][j+1]>max)
max=board[i+1][j+1];
}
}
}
return max*max;
}
public static void main(String[] args)
{
TryHelloWorld test = new TryHelloWorld();
char [][]board ={
{'X','O','O','O','X'},
{'X','O','O','O','O'},
{'X','X','O','O','O'},
{'X','X','O','O','O'},
{'X','X','X','X','X'}};
System.out.println(test.findLargestSquare(board));
}
}
|