Skip to content

Commit 08e0f0b

Browse files
committed
Time: 10 ms (54.97%), Space: 19.7 MB (25.73%) - LeetHub
1 parent 68c5e51 commit 08e0f0b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# time complexity: O(m * n)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def numberOfBeams(self, bank: List[str]) -> int:
8+
prev = 0
9+
laserSum = 0
10+
for row in bank:
11+
if row.count('1'):
12+
laserSum += prev * row.count('1')
13+
prev = row.count('1')
14+
return laserSum
15+
16+
17+
bank = ["011001", "000000", "010100", "001000"]
18+
print(Solution().numberOfBeams(bank))

0 commit comments

Comments
 (0)