这个题目用python来写的话,十分简单,代码如下:
用一个列表一个循环即可得接。后续可以考虑怎么才能省下空间复杂度,也就是目前是O(n+1)的空间复杂度。时间复杂度为O(N)
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 最大位数 # @return int整型一维数组 # class Solution: def printNumbers(self , n: int) -> List[int]: # write code here number=10**n-1 ls=[] i=0 while i<number: ls.append(i+1) i+=1 return ls