LeetCode 2125. Number of Laser Beams in a Bank
2023-04-23 03:37:55 哔哩哔哩

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.

热门推荐

文章排行

  1. 2023-04-23LeetCode 2125. Number of Laser Beams in a Bank
  2. 2023-04-23是否还会出现二次感染?抗体还有保护作用吗?张文宏最新解答!
  3. 2023-04-23AKIRA回应与林志玲生二胎:不是想生就能生 报资讯
  4. 2023-04-23环球快看:金银岛故事梗概50字_金银岛故事梗概
  5. 2023-04-23天天视讯!连输两盘直接出局!小德不敌同胞拉约维奇,赛后大方祝贺对手!
  6. 2023-04-23世界视讯!环球亚裔小姐大赛_关于环球亚裔小姐大赛介绍
  7. 2023-04-22胃肠型感冒的症状及用药_胃肠型感冒的症状及治疗
  8. 2023-04-22闲置泡泡点击什么时候出 公测上线时间预告|全球热点评
  9. 2023-04-22美银:强劲的个人支出将提振美国一季度经济
  10. 2023-04-22当前动态:2023中国网络媒体论坛在江苏南京举行
  11. 2023-04-224月23日上午“全民悦读邀您共读”第二季吉林省分会场直播,敬请期待!
  12. 2023-04-22当前短讯!伊朗与卡塔尔两国外长电话会谈
  13. 2023-04-22热点评!极危鸟类黄胸鹀现身东畔山洲
  14. 2023-04-22农村房屋取暖新方法_农村取暖新方法-环球实时
  15. 2023-04-22人民日报驻外记者:我经历的苏丹冲突乱局
  16. 2023-04-22助力乡村振兴,全国首家邮乐直播产业基地落户长沙
  17. 2023-04-22如何设置动态壁纸苹果平板_如何设置动态壁纸
  18. 2023-04-22世界地球日丨江源之上 守护麦秀林场_当前焦点
  19. 2023-04-22天天热讯:深圳大学在职研究生免试_深圳大学在职研究生
  20. 2023-04-22最新明确!核心区这类危旧楼房应腾退置换!东城这处老楼有望优先改造!