题解 | #无重复数组#

无重复数组

https://www.nowcoder.com/practice/d2fa3632268b41df9bc417b74802ad8c

const _getUniqueNums = (start,end,n) => {
                // 补全代码
                const result = []
                for(let i = 0; i < n; i++) {
                    let random = parseInt((Math.random() * (end - start) + start), 10)
                    while (result.includes(random)) {
                        random = parseInt((Math.random() * (end - start) + start), 10)
                    }
                    result.push(random)
                }
                return result
            }

全部评论

相关推荐

自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务