面试题17
示例 1:
输入: n = 1
输出: [1,2,3,4,5,6,7,8,9]说明:
Solutions
class Solution {
public:
vector<int> printNumbers(int n) {
int x = 10;
int maxn = 1;
// or maxn = pow(10, n) - 1
while (n) {
if (n & 1)
maxn *= x;
x *= x;
n >>= 1;
}
vector<int> res(maxn - 1);
for (int n = 1; n < maxn; n++)
res[n - 1] = n;
return res;
}
};Last updated