File tree 2 files changed +42
-1
lines changed
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,762 LeetCode solutions in JavaScript
1
+ # 1,763 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1627
1627
2121|[ Intervals Between Identical Elements] ( ./solutions/2121-intervals-between-identical-elements.js ) |Medium|
1628
1628
2122|[ Recover the Original Array] ( ./solutions/2122-recover-the-original-array.js ) |Hard|
1629
1629
2124|[ Check if All A's Appears Before All B's] ( ./solutions/2124-check-if-all-as-appears-before-all-bs.js ) |Easy|
1630
+ 2125|[ Number of Laser Beams in a Bank] ( ./solutions/2125-number-of-laser-beams-in-a-bank.js ) |Medium|
1630
1631
2127|[ Maximum Employees to Be Invited to a Meeting] ( ./solutions/2127-maximum-employees-to-be-invited-to-a-meeting.js ) |Hard|
1631
1632
2129|[ Capitalize the Title] ( ./solutions/2129-capitalize-the-title.js ) |Easy|
1632
1633
2130|[ Maximum Twin Sum of a Linked List] ( ./solutions/2130-maximum-twin-sum-of-a-linked-list.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2125. Number of Laser Beams in a Bank
3
+ * https://leetcode.com/problems/number-of-laser-beams-in-a-bank/
4
+ * Difficulty: Medium
5
+ *
6
+ * Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string
7
+ * array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i]
8
+ * represents the ith row, consisting of '0's and '1's. '0' means the cell is empty, while'1'
9
+ * means the cell has a security device.
10
+ *
11
+ * There is one laser beam between any two security devices if both conditions are met:
12
+ * - The two devices are located on two different rows: r1 and r2, where r1 < r2.
13
+ * - For each row i where r1 < i < r2, there are no security devices in the ith row.
14
+ *
15
+ * Laser beams are independent, i.e., one beam does not interfere nor join with another.
16
+ *
17
+ * Return the total number of laser beams in the bank.
18
+ */
19
+
20
+ /**
21
+ * @param {string[] } bank
22
+ * @return {number }
23
+ */
24
+ var numberOfBeams = function ( bank ) {
25
+ let result = 0 ;
26
+ let prevDevices = 0 ;
27
+
28
+ for ( const row of bank ) {
29
+ let currentDevices = 0 ;
30
+ for ( const cell of row ) {
31
+ if ( cell === '1' ) currentDevices ++ ;
32
+ }
33
+ if ( currentDevices > 0 ) {
34
+ result += prevDevices * currentDevices ;
35
+ prevDevices = currentDevices ;
36
+ }
37
+ }
38
+
39
+ return result ;
40
+ } ;
You can’t perform that action at this time.
0 commit comments