题解 | #无重复数组#
无重复数组
https://www.nowcoder.com/practice/d2fa3632268b41df9bc417b74802ad8c
考察随机数生成和去重问题
- 生成[n,m)区间的随机整数:Math.floor(Math.random()*(m-n))+n
- 生成[n,m]区间的随机整数:Math.floor(Math.random()*(m-n+1))+n
let set = new Set([]) while (set.size < n) { var num = Math.floor(Math.random() * ( end - start + 1 )) + start set.add(num) } return [...set]