File tree Expand file tree Collapse file tree 1 file changed +4
-10
lines changed
solution/1500-1599/1562.Find Latest Group of Size M Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -291,11 +291,8 @@ func findLatestStep(arr []int, m int) int {
291
291
292
292
#### JavaScript
293
293
294
- ``` javascript
294
+ ``` js
295
295
const findLatestStep = function (arr , m ) {
296
- let p = [];
297
- let size = [];
298
-
299
296
function find (x ) {
300
297
if (p[x] !== x) {
301
298
p[x] = find (p[x]);
@@ -317,12 +314,9 @@ const findLatestStep = function (arr, m) {
317
314
if (m === n) {
318
315
return n;
319
316
}
320
- const vis = new Array (n).fill (false );
321
- p = new Array (n);
322
- size = new Array (n).fill (1 );
323
- for (let i = 0 ; i < n; ++ i) {
324
- p[i] = i;
325
- }
317
+ const vis = Array (n).fill (false );
318
+ const p = Array .from ({ length: n }, (_ , i ) => i);
319
+ const size = Array (n).fill (1 );
326
320
let ans = - 1 ;
327
321
for (let i = 0 ; i < n; ++ i) {
328
322
const v = arr[i] - 1 ;
You can’t perform that action at this time.
0 commit comments