Skip to content

Commit b0ed8ed

Browse files
authored
Create 2125. Number of Laser Beams in a Bank.cpp
1 parent 8ef3e89 commit b0ed8ed

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int numberOfBeams(vector<string>& bank) {
4+
int result=0;
5+
vector<int> v;
6+
for(const auto& a:bank) {
7+
int cnt=count(a.begin(),a.end(),'1');
8+
if(cnt!=0)
9+
{
10+
v.push_back(cnt);
11+
}
12+
}
13+
for(size_t i=1;i<v.size();++i) {
14+
result+=v[i]*v[i-1];
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)