Skip to content

Commit c05d570

Browse files
committed
add max squre
1 parent b3c6f4f commit c05d570

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

maximal-square/README.md

Whitespace-only changes.

maximal-square/Solution.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
public class Solution {
2+
3+
int maximalSquare(char[][] matrix, final int x, final int y){
4+
int l = 1;
5+
6+
done:
7+
while(true){
8+
9+
for(int i = 0; i <= l; i++){
10+
11+
if(x + l >= matrix.length || y + l >= matrix[0].length){
12+
break done;
13+
}
14+
15+
16+
if(matrix[x + l][y + i] != '1'){
17+
break done;
18+
}
19+
20+
if(matrix[x + i][y + l] != '1'){
21+
break done;
22+
}
23+
24+
}
25+
26+
l++;
27+
}
28+
29+
return l * l;
30+
}
31+
32+
public int maximalSquare(char[][] matrix) {
33+
34+
int max = 0;
35+
36+
for(int x = 0; x < matrix.length; x++){
37+
for(int y = 0; y < matrix[0].length; y++){
38+
if(matrix[x][y] == '1'){
39+
max = Math.max(max, maximalSquare(matrix, x, y));
40+
}
41+
}
42+
}
43+
44+
return max;
45+
}
46+
}

maximal-square/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: solution
3+
title: Maximal Square
4+
date: 2015-06-04 23:46:46+08:00
5+
leetcode_id: 221
6+
---
7+
{% include_relative README.md %}

0 commit comments

Comments
 (0)