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

打印从1到最大的n位数

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

import java.util.*;


public class Solution {
    public int[] printNumbers (int n) {
        // write code here
        // 找到该n+1位的最小数字
        int end = 1;
        for(int i = 1; i <= n; i++){
            end *= 10;
        }
        // 从1遍历到n+1位数的最小数字输出
        int[] res = new int[end - 1];
        for(int i = 1; i < end; i++){
            res[i - 1] = i;
        }
        return res;
    }
}

全部评论

相关推荐

06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 18:02
好不容易拿到了字节Offer,鼠鼠做后端的,但家里人觉得可能被裁员不稳定,让鼠鼠去投国企,现在好纠结到底该咋选
文档传偷助手:该投就投吧,不过建议别放弃offer 拿到手里的才是最好的
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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