leetcode

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

1582.cpp (662B)


0 class Solution { 1 public: 2 int numSpecial(const vector<vector<int>> &mat) const { 3 const int n = mat.size(), m = mat[0].size(); 4 int row[101] = {0}, col[101] = {0}; 5 6 for (int i = 0; i < n; i++) { 7 for (int j = 0; j < m; j++) { 8 if (mat[i][j]) { 9 row[i]++; 10 col[j]++; 11 } 12 } 13 } 14 15 int res = 0; 16 for (int i = 0; i < n; i++) { 17 for (int j = 0; j < m; j++) { 18 if (mat[i][j] && row[i] == 1 && col[j] == 1) { 19 res++; 20 } 21 } 22 } 23 return res; 24 } 25 };