leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1277.cpp (484B)


      1 class Solution {
      2   public:
      3     int countSquares(vector<vector<int>> &matrix) const {
      4         const int n = size(matrix), m = size(matrix[0]);
      5         int res = 0;
      6 
      7         for (int i = 0; i < n; i++) {
      8             for (int j = 0; j < m; res += matrix[i][j], j++) {
      9                 if (matrix[i][j] && i && j) {
     10                     matrix[i][j] += min({matrix[i - 1][j - 1], matrix[i - 1][j], matrix[i][j - 1]});
     11                 }
     12             }
     13         }
     14 
     15         return res;
     16     }
     17 };