File tree Expand file tree Collapse file tree 1 file changed +3
-14
lines changed
solution/1500-1599/1562.Find Latest Group of Size M Expand file tree Collapse file tree 1 file changed +3
-14
lines changed Original file line number Diff line number Diff line change 1
- /**
2
- * @param {number[] } arr
3
- * @param {number } m
4
- * @return {number }
5
- */
6
1
const findLatestStep = function ( arr , m ) {
7
- let p = [ ] ;
8
- let size = [ ] ;
9
-
10
2
function find ( x ) {
11
3
if ( p [ x ] !== x ) {
12
4
p [ x ] = find ( p [ x ] ) ;
@@ -28,12 +20,9 @@ const findLatestStep = function (arr, m) {
28
20
if ( m === n ) {
29
21
return n ;
30
22
}
31
- const vis = new Array ( n ) . fill ( false ) ;
32
- p = new Array ( n ) ;
33
- size = new Array ( n ) . fill ( 1 ) ;
34
- for ( let i = 0 ; i < n ; ++ i ) {
35
- p [ i ] = i ;
36
- }
23
+ const vis = Array ( n ) . fill ( false ) ;
24
+ const p = Array . from ( { length : n } , ( _ , i ) => i ) ;
25
+ const size = Array ( n ) . fill ( 1 ) ;
37
26
let ans = - 1 ;
38
27
for ( let i = 0 ; i < n ; ++ i ) {
39
28
const v = arr [ i ] - 1 ;
You can’t perform that action at this time.
0 commit comments