题目
输入数字 n,按顺序打印出从 1 到最大的 n 位十进制数。比如输入 3,则打印出 1、2、3 一直到最大的 3 位数 999。
示例 1:
1
2 输入: 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
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
这题目跟书上题目完全不一样了,无意义。
思路
题目考察大数运算,使用字符串进行模拟运算,或者转化成回溯问题使用递归解决。
字符串解法
1 | /* 基于字符串的加法模拟 */ |
递归解法
递归实现:
1 | /* 递归实现 */ |
思路是从最高位开始,对每一位进行全排列。