题解 | #无重复数组#

无重复数组

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
            }

全部评论

相关推荐

找到实习就改名4月17日下午更改:1600一个月?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务