參考鏈接
- std::iota
- std::iota用法學習
- 劍指 Offer 17. 打印從1到最大的n位數
輸入數字 n,按順序打印出從 1 到最大的 n 位十進制數。比如輸入 3,則打印出 1、2、3 一直到最大的 3 位數 999。
示例 1:
輸入: n = 1
輸出: [1,2,3,4,5,6,7,8,9]
?說明:
用返回一個整數列表來代替打印
n 為正整數
來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof
著作權歸領扣網絡所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
std::vector<int> printNumbers(int n) {std::vector<int>res(pow(10,n)-1,0);std::iota(res.begin(),res.end(),1);return res;
}
?