题解 | #无重复数组#

无重复数组

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n    <meta charset=\"UTF-8\">\n</head>\n\n<body>\n\n    <script>\n        const _getUniqueNums = (start, end, n) => {\n            let arr = []\n            let ran = 0\n            // 补全代码\n            // debugger\n            for (let i = 0; arr.length !== n; i++) {\n                ran = Math.floor(Math.random() * (end - start) + start + 1)\n                // debugger\n                for (let j = 0; arr.length !== n; j++) {\n                    if (ran === arr[j]) {\n                        break\n                    }\n                    if (j === arr.length) {\n                        arr.push(ran)\n                        break\n                    }\n                }\n            }\n            console.log(arr);\n            return arr\n        }\n        _getUniqueNums(10, 16, 5)\n    </script>\n</body>\n\n</html>","libs":[]}

全部评论

相关推荐

10-13 17:47
门头沟学院 Java
wulala.god:图一那个善我面过,老板网上找的题库面的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务