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)


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