Skip to content

Commit 94f0a4d

Browse files
authored
Update 2552-count-increasing-quadruplets.js
1 parent b6173e7 commit 94f0a4d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2552-count-increasing-quadruplets.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const countQuadruplets = function(nums) {
6+
let res = 0, n = nums.length
7+
const cnt = Array(n).fill(0)
8+
9+
for(let j = 0; j < n; j++) {
10+
let preSmall = 0
11+
for(let i = 0; i < j; i++) {
12+
if(nums[i] < nums[j]) {
13+
preSmall++
14+
res += cnt[i]
15+
} else if(nums[j] < nums[i]) {
16+
cnt[i] += preSmall
17+
}
18+
}
19+
}
20+
21+
return res
22+
};
23+
24+
// another
25+
126
/**
227
* @param {number[]} nums
328
* @return {number}

0 commit comments

Comments
 (0)