-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1277.cpp
More file actions
28 lines (28 loc) · 776 Bytes
/
1277.cpp
File metadata and controls
28 lines (28 loc) · 776 Bytes
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
class Solution {
public:
int countSquares(vector<vector<int>>& matrix) {
int n=matrix.size();
int m=matrix[0].size();
long long int A[n+1][m+1];
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0 || j==0){
A[i][j]=0;
}
else if(matrix[i-1][j-1]==0){
A[i][j]=0;
}
else if(matrix[i-1][j-1]==1){
A[i][j]=min(A[i-1][j-1] , min(A[i-1][j],A[i][j-1])) + 1;
}
}
}
long long int sum=0;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
sum+=A[i][j];
}
}
return sum;
}
};