We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9e1dcde commit d282f5fCopy full SHA for d282f5f
C++/special-positions-in-a-binary-matrix.cpp
@@ -0,0 +1,25 @@
1
+// Time: O(n^2)
2
+// Space: O(n)
3
+
4
+class Solution {
5
+public:
6
+ int numSpecial(vector<vector<int>>& mat) {
7
+ vector<int> rows(size(mat)), cols(size(mat[0]));
8
+ for (int i = 0; i < size(rows); ++i) {
9
+ for (int j = 0; j < size(cols); ++j) {
10
+ if (mat[i][j]) {
11
+ ++rows[i], ++cols[j];
12
+ }
13
14
15
+ int result = 0;
16
17
18
+ if (mat[i][j] && rows[i] == 1 && cols[j] == 1) {
19
+ ++result;
20
21
22
23
+ return result;
24
25
+};
0 commit comments