public class Solution {
int[] res ;
int n;
int count=0;
char[]num,loop= {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
public int[] printNumbers(int n) {
this.n = n;
res = new int[(int)Math.pow(10,n)-1];
num = new char[n];
dfs(0);
return res;
}
void dfs(int x) {
if(x==n) {
String str = String.valueOf(num).replaceAll("^(0+)", "");
if(str.length()==0)
return ;
else
res[count++] = Integer.parseInt(str);
return ;
}
for(char i : loop) {
num[x] = i;
dfs(x+1);
}
}
}
打印从 1 到最大的 n 位数
于 2022-02-28 16:16:19 首次发布