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 @@ -271,11 +271,8 @@ func findLatestStep(arr []int, m int) int {
271
271
272
272
#### JavaScript
273
273
274
- ``` javascript
274
+ ``` js
275
275
const findLatestStep = function (arr , m ) {
276
- let p = [];
277
- let size = [];
278
-
279
276
function find (x ) {
280
277
if (p[x] !== x) {
281
278
p[x] = find (p[x]);
@@ -297,12 +294,9 @@ const findLatestStep = function (arr, m) {
297
294
if (m === n) {
298
295
return n;
299
296
}
300
- const vis = new Array (n).fill (false );
301
- p = new Array (n);
302
- size = new Array (n).fill (1 );
303
- for (let i = 0 ; i < n; ++ i) {
304
- p[i] = i;
305
- }
297
+ const vis = Array (n).fill (false );
298
+ const p = Array .from ({ length: n }, (_ , i ) => i);
299
+ const size = Array (n).fill (1 );
306
300
let ans = - 1 ;
307
301
for (let i = 0 ; i < n; ++ i) {
308
302
const v = arr[i] - 1 ;
You can’t perform that action at this time.
0 commit comments