Skip to content

Commit c68441b

Browse files
committed
Update index.ts
1 parent 6b8bf4a commit c68441b

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

find-all-good-indices/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,29 @@ export default function goodIndices(nums: number[], k: number): number[] {
88
for (let i = 0; i < pre.length; i++) {
99
if (i === 0) {
1010
for (let j = 1; j < k; j++) {
11-
// console.log('pre')
1211
pre[i] = nums[j] <= nums[j - 1] ? pre[i] + 1 : 1;
1312
}
1413
} else {
1514
const j = i + k - 1;
16-
// console.log(j,j-1)
17-
// console.log(i)
15+
1816
pre[i] = nums[j] <= nums[j - 1] ? pre[i - 1] + 1 : 1;
1917
}
2018
}
2119
for (let i = 0; i < post.length; i++) {
2220
if (i === 0) {
2321
for (let j = n - 2; j > n - k - 1; j--) {
24-
// console.log('post')
2522
post[post.length - 1 - i] = nums[j] <= nums[j + 1]
2623
? post[post.length - 1 - i] + 1
2724
: 1;
2825
}
2926
} else {
3027
const j = nums.length - i - k;
31-
// console.log(j,j+1)
32-
// console.log(nums[j+1],nums[j+2],nums[j+1] <= nums[j + 2])
33-
// console.log()
34-
// console.log(post.length - 1 - i)
28+
3529
post[post.length - 1 - i] = nums[j] <= nums[j + 1]
3630
? post[post.length - i] + 1
3731
: 1;
3832
}
3933
}
40-
// console.log(pre, post)
4134

4235
return [...Array(n - k * 2).keys()]
4336
.filter((i) => pre[i] >= k && post[i] >= k)

0 commit comments

Comments
 (0)