Skip to content

Commit d0b3391

Browse files
authored
Update 992-subarrays-with-k-different-integers.js
1 parent 6477517 commit d0b3391

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

992-subarrays-with-k-different-integers.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
* @return {number}
55
*/
66
const subarraysWithKDistinct = function(A, K) {
7-
let res = 0,
8-
prefix = 0
7+
let res = 0
8+
let prefix = 0
99
const m = new Array(A.length + 1).fill(0)
10-
for (let i = 0, j = 0, cnt = 0; i < A.length; ++i) {
11-
if (m[A[i]]++ === 0) ++cnt
10+
for (let i = 0, j = 0, cnt = 0; i < A.length; i++) {
11+
if (m[A[i]]++ === 0) cnt++
1212
if (cnt > K) {
13-
--m[A[j++]]
14-
--cnt
13+
m[A[j++]]--
14+
cnt--
1515
prefix = 0
1616
}
1717
while (m[A[j]] > 1) {
18-
++prefix
19-
--m[A[j++]]
18+
prefix++
19+
m[A[j++]]--
2020
}
2121
if (cnt === K) res += prefix + 1
2222
}

0 commit comments

Comments
 (0)