Skip to content

Commit cca3054

Browse files
authored
Update 2963-count-the-number-of-good-partitions.js
1 parent d40cce1 commit cca3054

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

2963-count-the-number-of-good-partitions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const numberOfGoodPartitions = function(nums) {
6+
const n = nums.length, mod = 1e9 + 7, lastIdxHash = {}
7+
let res = 1
8+
for (let i = 0; i < n; i++) lastIdxHash[nums[i]] = i
9+
let j = 0
10+
for(let i = 0; i < n; i++) {
11+
if(i > j) res = (res * 2) % mod
12+
j = Math.max(j, lastIdxHash[nums[i]])
13+
}
14+
15+
16+
return res
17+
};
18+
19+
// another
20+
121
class Interval {
222
constructor(left, right) {
323
this.left = left

0 commit comments

Comments
 (0)