-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_1582_numSpecial.cc
More file actions
54 lines (49 loc) · 970 Bytes
/
Problem_1582_numSpecial.cc
File metadata and controls
54 lines (49 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <vector>
#include "UnitTest.h"
using namespace std;
class Solution
{
public:
int numSpecial(vector<vector<int>> &mat)
{
int N = mat.size();
int M = mat[0].size();
vector<int> rowSum(N);
vector<int> colSum(M);
int ans = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
rowSum[i] += mat[i][j];
colSum[j] += mat[i][j];
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
if (mat[i][j] == 1 && rowSum[i] == 1 && colSum[j] == 1)
{
ans++;
}
}
}
return ans;
}
};
void testNumSpecial()
{
Solution s;
vector<vector<int>> mat1 = {{1, 0, 0}, {0, 0, 1}, {1, 0, 0}};
vector<vector<int>> mat2 = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
EXPECT_EQ_INT(1, s.numSpecial(mat1));
EXPECT_EQ_INT(3, s.numSpecial(mat2));
EXPECT_SUMMARY;
}
int main()
{
testNumSpecial();
return 0;
}