Skip to content

Commit bd72a11

Browse files
committed
Time: 71 ms (93.43%), Space: 23.7 MB (78.08%) - LeetHub
1 parent 0088a7a commit bd72a11

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int countSquares(vector<vector<int>>& matrix) {
4+
5+
int count = 0;
6+
int n = matrix.size(), m = matrix[0].size();
7+
8+
for(int i = 0; i<n; ++i)
9+
{
10+
for(int j = 0; j<m; ++j)
11+
{
12+
if(i > 0 and j > 0 and matrix[i][j] > 0)
13+
{
14+
matrix[i][j] = min({matrix[i-1][j-1],matrix[i-1][j], matrix[i][j-1]}) + 1;
15+
}
16+
count += matrix[i][j];
17+
}
18+
}
19+
return count;
20+
}
21+
};
22+

0 commit comments

Comments
 (0)