Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b9fd38

Browse files
committed
Add solution #2125
1 parent b43b927 commit 0b9fd38

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,762 LeetCode solutions in JavaScript
1+
# 1,763 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1627,6 +1627,7 @@
16271627
2121|[Intervals Between Identical Elements](./solutions/2121-intervals-between-identical-elements.js)|Medium|
16281628
2122|[Recover the Original Array](./solutions/2122-recover-the-original-array.js)|Hard|
16291629
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|
16301631
2127|[Maximum Employees to Be Invited to a Meeting](./solutions/2127-maximum-employees-to-be-invited-to-a-meeting.js)|Hard|
16311632
2129|[Capitalize the Title](./solutions/2129-capitalize-the-title.js)|Easy|
16321633
2130|[Maximum Twin Sum of a Linked List](./solutions/2130-maximum-twin-sum-of-a-linked-list.js)|Medium|
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
};

0 commit comments

Comments
 (0)