forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecial Positions in a Binary Matrix.cpp
43 lines (41 loc) · 1.11 KB
/
Special Positions in a Binary Matrix.cpp
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
// Runtime: 67 ms (Top 10.18%) | Memory: 18.5 MB (Top 5.36%)
class Solution {
public:
int numSpecial(vector<vector<int>>& mat) {
vector<vector<int>>v;
map<int,vector<int>>m;
for(int i=0;i<mat.size();i++){
vector<int>temp = mat[i];
for(int j=0;j<temp.size();j++){
m[j].push_back(temp[j]);
}
}
for(auto i:m){
v.push_back(i.second);
}
int counter = 0;
for(int i=0;i<mat.size();i++){
int onecount = 0;
int column = 0;
for(int j=0;j<mat[i].size();j++){
if(mat[i][j]==1){
column = j;
onecount++;
}
}
if(onecount==1){
int countone = 0;
vector<int>temp = v[column];
for(auto i:temp){
if(i==1){
countone++;
}
}
if(countone==1){
counter++;
}
}
}
return counter;
}
};