题解 | #打印从1到最大的n位数#

打印从1到最大的n位数

http://www.nowcoder.com/practice/4436c93e568c48f6b28ff436173b997f

打印从1到最大的n位数做到两点即可

1: 获取最大值 max = 10**n-1;

2:建空数组,循环max,添加到数组中即可
function printNumbers( n ) {
    // write code here
    let max = 10**n-1;
    let arr=[];
    let i=0;
    while (i<max){
      arr.push(i+1)
      i+=1
    }
    return arr
    
}
module.exports = {
    printNumbers : printNumbers
};


全部评论

相关推荐

996的工作制还是没能硬啃下去,快要面试怂了,取消了
牛客80700350...:很正常,不是所有人都能接受这种强度的。不叫怯战,这叫明智
点赞 评论 收藏
分享
再懒也要睡懒觉:大学4年玩的挺爽的哈😅
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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