Skip to content

Commit 0fb6b09

Browse files
authored
Create 3027-find-the-number-of-ways-to-place-people-ii.js
1 parent d5db534 commit 0fb6b09

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number[][]} points
3+
* @return {number}
4+
*/
5+
var numberOfPairs = function(points) {
6+
points.sort((a, b) => {
7+
if (a[0] === b[0]) return b[1] - a[1];
8+
return a[0] - b[0];
9+
});
10+
11+
let solution = 0;
12+
for (let i = 0; i < points.length; i++) {
13+
let c = points[i];
14+
let currentMax = -Infinity;
15+
for (let j = i + 1; j < points.length; j++) {
16+
let t = points[j];
17+
if (c[1] < t[1]) continue;
18+
if (currentMax >= t[1]) continue;
19+
currentMax = Math.max(currentMax, t[1]);
20+
solution++;
21+
}
22+
}
23+
24+
return solution;
25+
};

0 commit comments

Comments
 (0)