题解 | #打印从1到最大的n位数#
打印从1到最大的n位数
http://www.nowcoder.com/practice/4436c93e568c48f6b28ff436173b997f
这个题目用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