LeetCode 2125. Number of Laser Beams in a Bank|当前热文

2023-04-23 03:50:25 | 来源:哔哩哔哩

Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bankrepresenting the floor plan of the bank, which is an m x n2D matrix. bank[i]represents the ithrow, consisting of '0's and '1's. '0'means the cell is empty, while'1'means the cell has a security device.

There is one laser beam between any two security devices if both conditions are met:


(相关资料图)

The two devices are located on two different rows: r1and r2, where r1 < r2.

For each row iwhere r1 < i < r2, there are no security devices in the ithrow.

Laser beams are independent, i.e., one beam does not interfere nor join with another.

Return the total number of laser beams in the bank.

Example 1:

Input: bank = ["011001","000000","010100","001000"]

Output: 8

Explanation: 

Between each of the following device pairs, there is one beam. 

In total, there are 8 beams: 

* bank[0][1] -- bank[2][1] 

* bank[0][1] -- bank[2][3] 

* bank[0][2] -- bank[2][1] 

* bank[0][2] -- bank[2][3] 

* bank[0][5] -- bank[2][1] 

* bank[0][5] -- bank[2][3] 

* bank[2][1] -- bank[3][2]

* bank[2][3] -- bank[3][2] 

Note that there is no beam between any device on the 0th row with any on the 3rd row.This is because the 2nd row contains security devices, which breaks the second condition.

Example 2:

Input: bank = ["000","111","000"]

Output: 0

Explanation: There does not exist two devices located on two different rows.

Constraints:

m == bank.length

n == bank[i].length

1 <= m, n <= 500

bank[i][j]is either '0'or '1'.

主要就是判断每一层对应的激光机器的数量;

这里用list去存储,

如果list的大小<2,那么就没有激光;

如果>2,就是遍历每一层跟下面一层的数量,乘积最后求和,返回即可;

下面是代码:

Runtime: 12 ms, faster than 99.09% of Java online submissions for Number of Laser Beams in a Bank.

Memory Usage: 43.4 MB, less than 26.14% of Java online submissions for Number of Laser Beams in a Bank.

上一篇 下一篇

相关新闻

LeetCode 2125. Number of Laser Beams in a Bank|当前热文

世界微头条丨山西右玉县举办文旅产业招商推介暨“右玉生态羊”品牌推广活动

天天微动态丨适合中老年人的发型_你可知道

天天短讯!碧奥春天是哪个国家的品牌_什么档次怎么样

环球影讯_关于环球影讯介绍|全球快看

张馨予演妲己是什么电视剧_你都看过吗_世界微速讯

动态:关于处暑节气的诗句古诗_关于处暑节气的诗句

世界即时看!葡萄干放久了还能吃吗 葡萄干的保质期多久

麒盛科技(603610):麒盛科技第三届董事会第三次会议决议 焦点速看

【扬子专栏:KPL最前沿】临阵换将激发新潜力 南京Hero零封长沙TES提前锁定季后赛|世界今头条

邵东:同课异构展风采,教研交流促成长

如何更改qq皮肤_更改皮肤方法

全球新动态:丹寨县气象台发布大风蓝色预警信号【Ⅳ/一般】

电脑设置密码忘记了怎么办

当前热门:生了冻疮的手怎么恢复_冻疮手指变粗怎么简单快速恢复

最新新闻

LeetCode 2125. Number of Laser Beams in a Bank|当前热文

世界微头条丨山西右玉县举办文旅产业招商推介暨“右玉生态羊”品牌推广活动

天天微动态丨适合中老年人的发型_你可知道

天天短讯!碧奥春天是哪个国家的品牌_什么档次怎么样

环球影讯_关于环球影讯介绍|全球快看

张馨予演妲己是什么电视剧_你都看过吗_世界微速讯

动态:关于处暑节气的诗句古诗_关于处暑节气的诗句

世界即时看!葡萄干放久了还能吃吗 葡萄干的保质期多久

麒盛科技(603610):麒盛科技第三届董事会第三次会议决议 焦点速看

【扬子专栏:KPL最前沿】临阵换将激发新潜力 南京Hero零封长沙TES提前锁定季后赛|世界今头条

邵东:同课异构展风采,教研交流促成长

如何更改qq皮肤_更改皮肤方法

全球新动态:丹寨县气象台发布大风蓝色预警信号【Ⅳ/一般】

电脑设置密码忘记了怎么办

当前热门:生了冻疮的手怎么恢复_冻疮手指变粗怎么简单快速恢复

重庆瞭望|4.7%,开局稳进!

全球聚焦:菲律宾马尼拉房价大跌2021年_菲律宾马尼拉房价大跌

张维为:我们正在见证和参与“时代巨变”

快播:停电入侵地球豆瓣_停电入侵地球

记者:拜仁中锋引援首选奥斯梅恩,穆阿尼和霍伊伦德是备选

家用空调如何选择_如何选择空调

品广陵十二时辰,鉴运河十二美景 2023“苏新消费家电家装嘉年华”扬州站闪耀启动|关注

环球视讯!怎样生黄豆芽_具体怎么操作

今日聚焦!科创板首批强制退市案:泽达易盛财务造假持续6年,虚增营业收入和利润,相关责任人被惩处|财务异动透视镜

世界今头条!追梦被禁赛,勇士找到赢球密码,三叉戟统治力仍在,科尔该醒悟了

今热点:饼干面团冰棒食谱

南怀瑾老师:我在运气最好时做这个事,一辈子放在第一位 环球讯息

安徽一局长直播调查研究,13.6万人次围观-环球时讯

老杜南京武汉各处游,智障大女儿谁照顾 世界通讯

海飘雪的所有作品 海飘雪