题解 | #打印从1到最大的n位数#
打印从1到最大的n位数
https://www.nowcoder.com/practice/4436c93e568c48f6b28ff436173b997f
解题思路
- 暴力解决即可。
复杂度
- 时间复杂度为O(10^n);
- 空间复杂度为O(1),除结果所需的空间外,没有借助其他的额外空间。
代码
Python
class Solution: def printNumbers(self , n: int) -> List[int]: res = [] for i in range(1, 10**n): res.append(i) return res
C++
class Solution { public: vector<int> printNumbers(int n) { vector<int> res; for(int i = 1; i < pow(10, n); i++) { res.push_back(i); } return res; } };