第 57 日:打印从1到最大的n位数
题目链接:https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/
题目
解题
-
循环
解题思路:
直接根据位数,求出他的边界,再循环存值就好了!详细代码如下:
class Solution {
public int[] printNumbers(int n) {
int max=(int)Math.pow(10,n)-1;
int[] res=new int[max];
for(int i=0;i<max;i++){
res[i]=i+1;
}
return res;
}
}