File tree Expand file tree Collapse file tree 1 file changed +2
-9
lines changed Expand file tree Collapse file tree 1 file changed +2
-9
lines changed Original file line number Diff line number Diff line change @@ -8,36 +8,29 @@ export default function goodIndices(nums: number[], k: number): number[] {
8
8
for ( let i = 0 ; i < pre . length ; i ++ ) {
9
9
if ( i === 0 ) {
10
10
for ( let j = 1 ; j < k ; j ++ ) {
11
- // console.log('pre')
12
11
pre [ i ] = nums [ j ] <= nums [ j - 1 ] ? pre [ i ] + 1 : 1 ;
13
12
}
14
13
} else {
15
14
const j = i + k - 1 ;
16
- // console.log(j,j-1)
17
- // console.log(i)
15
+
18
16
pre [ i ] = nums [ j ] <= nums [ j - 1 ] ? pre [ i - 1 ] + 1 : 1 ;
19
17
}
20
18
}
21
19
for ( let i = 0 ; i < post . length ; i ++ ) {
22
20
if ( i === 0 ) {
23
21
for ( let j = n - 2 ; j > n - k - 1 ; j -- ) {
24
- // console.log('post')
25
22
post [ post . length - 1 - i ] = nums [ j ] <= nums [ j + 1 ]
26
23
? post [ post . length - 1 - i ] + 1
27
24
: 1 ;
28
25
}
29
26
} else {
30
27
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
+
35
29
post [ post . length - 1 - i ] = nums [ j ] <= nums [ j + 1 ]
36
30
? post [ post . length - i ] + 1
37
31
: 1 ;
38
32
}
39
33
}
40
- // console.log(pre, post)
41
34
42
35
return [ ...Array ( n - k * 2 ) . keys ( ) ]
43
36
. filter ( ( i ) => pre [ i ] >= k && post [ i ] >= k )
You can’t perform that action at this time.
0 commit comments