题目描述
输入数组n,按顺序打印出从1到最大n位十进制数。
比如输入3,则打印出1、2、3一直到最大的3位数999.
lc练习
实现
低效 问题-n很大 大数问题
执行用时:1 ms, 在所有 Java 提交中击败了100.00%的用户
内存消耗:46.9 MB, 在所有 Java 提交中击败了15.52%的用户
public int[] printNumbers(int n) {
int num = 1;
int i = 0;
while (i++ < n) {
num *= 10;
}
int[] res = new int[num - 1];
int j = 1;
while (j < num) {
res[j - 1] = j;
j++;
}
return res;
}
-----------------------------------------------------------
class Solution {
public int[] printNumbers(int n) {
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;
}
}
链接:https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/solution/mian-shi-ti-17-da-yin-cong-1-dao-zui-da-de-n-wei-2/
解决大数问题
使用字符串/数组表示大数
未完待续…