2125. Number of Laser Beams in a Bank
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 85% Topics: Array, Math, String, Matrix
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(m * n)
# Space: O(1)
class Solution(object):
def numberOfBeams(self, bank):
"""
:type bank: List[str]
:rtype: int
"""
result = prev = 0
for x in bank:
cnt = x.count('1')
if not cnt:
continue
result += prev*cnt
prev = cnt
return result
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions