Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int countSquares(vector<vector<int>>& mat) {
- int rows = mat.size(), cols = mat[0].size();
- int count = 0;
- int dp[rows][cols];
- for(int i=0; i<rows; i++){
- for(int j=0; j<cols; j++){
- dp[i][j] = mat[i][j];
- if(mat[i][j] && i && j){
- int sz = min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]});
- dp[i][j] = sz+1;
- }
- count += dp[i][j];
- }
- }
- return count;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment