剑指 Offer 17. 打印从1到最大的n位数
2021-10-20 本文已影响0人
ttiga

此方法不用考虑大数边界问题
class Solution {
public int[] printNumbers(int n) {
// 最大值为10的n次方减1
int end = (int)Math.pow(10,n) - 1;
// 按照输入的值创建数组大小
int[] res = new int[end];
// 循环将每一个数放入数组中
for(int i = 0;i < end;i++){
res[i] = i + 1;
}
return res;
}
}
``