Python | easy explanation | easy solution
Runtime: 87 ms, faster than 93.99% of Python3 online submissions for Number of Laser Beams in a Bank.\nMemory Usage: 15.9 MB, less than 90.75% of Python3 online
Runtime: 87 ms, faster than **93.99%** of Python3 online submissions for Number of Laser Beams in a Bank.\nMemory Usage: 15.9 MB, less than **90.75%** of Python3 online submissions for Number of Laser Beams in a Bank.\n\nPretty self explanatory code. We itterate over bank and count occurence of 1\'s in each string. \nmultiply it with previously row count and add it to result. update the previous row count.\n\n***Leave an upvote if this helps!!!***\n\n```\nclass Solution:\n    def numberOfBeams(self, bank: List[str]) -> int:\n        pre = 0\n        nn = 0\n        ans = 0\n        for i in bank:\n            nn=i.count(\'1\')\n            if nn:\n                ans+=nn*pre\n                pre= nn\n        return ans\n```\n\n
['Python']