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