题解 | #无重复数组#
无重复数组
https://www.nowcoder.com/practice/d2fa3632268b41df9bc417b74802ad8c
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script> const _getUniqueNums = (start,end,n) => { // 补全代码 let arr = []; let res = []; for(let i = start; i<=end; i++){ arr.push(i); } while(res.length!=n){ let randomindex = Math.round(Math.random()*arr.length); res.push(arr[randomindex]); arr.splice(randomindex,1); } return res; } </script> </body> </html>