题目链接 https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/ 解题思路 直接从1开始遍历到 1 0 n − 1 10^n-1 10n−1 AC代码 class Solution { public int[] printNumbers(int n) { int[] ans = new int[(int) Math.pow(10, n) - 1]; for (int i = 1; i < Math.pow(10, n); i++) { ans[i - 1] = i; } return ans; } } 本地测试代码 package com.company; import java.util.Arrays; public class Solution_1661 { public static int[] printNumbers(int n) { int[] ans = new int[(int) Math.pow(10, n) - 1]; for (int i = 1; i < Math.pow(10, n); i++) { ans[i - 1] = i; } return ans; } public static void main(String[] args) { System.out.println(Arrays.toString(printNumbers(1))); } }