题解 | #无重复数组#
无重复数组
https://www.nowcoder.com/practice/d2fa3632268b41df9bc417b74802ad8c
const _getUniqueNums = (start,end,n) => { end - 1; lst = [] // 补全代码 while(true){ let num = Math.floor(Math.random() * end) + start; if(lst.includes(num)) continue; lst.push(num); n--; if(n === 0) break; } return lst }
循环生成随机数并存入数组中即可,如遇到重复的直接跳过进入下一次循环