Print Numbers by Recursion
来源:互联网 发布:Windows mr 编辑:程序博客网 时间:2024/06/18 00:44
Print Numbers by Recursion
Print numbers from 1 to the largest number with N digits by recursion.
Notice
It's pretty easy to do recursion like:
recursion(i) { if i > largest number: return results.add(i) recursion(i + 1)}
however this cost a lot of recursion memory as the recursion depth maybe very large. Can you do it in another way to recursive with at most N depth?
Given N = 1
, return [1,2,3,4,5,6,7,8,9]
.
Given N = 2
, return [1,2,3,4,5,6,7,8,9,10,11,12,...,99]
.
非递归方法 也还可以
/** * Created by jason on 2016/3/6. */class Solution68 { public List<Integer> numbersByRecursion(int n) { int N=1; for (int i=1; i<=n; i++) { N = N*10; } N = N-1; List<Integer> result = new ArrayList<Integer>(); for (int i=1; i<=N; i++) { result.add(i); } return result; }}
0 0
- Print Numbers by Recursion
- Print Numbers by Recursion
- Print Numbers by Recursion
- lintcode:Print Numbers by Recursion
- #371 Print Numbers by Recursion
- [LintCode]Print Numbers by Recursion
- Print Numbers by Recursion 解题报告
- [剑指offer][第三章][12] Print Numbers by Recursion
- [LintCode] 用递归打印数字 Print Numbers by Recursion
- 371.Print Numbers by Recursion-用递归打印数字(中等题)
- Go by Example: Recursion
- print all permutation of a string(recursion)
- Recursion
- Recursion
- Recursion
- Recursion
- Recursion
- Recursion
- 【线段树模板!!!】hdu-1394 顺便学习一下not only succes 的线段树风格
- android国际化(多语言)
- Linux内核分析——操作系统进程调度
- 文件系统类型汇总
- Binary Expression and Value Expression
- Print Numbers by Recursion
- UIActivityIndicatorView的使用
- SharePoint 2010 - Hardware and Software Requirements
- iOS 一次上传多张图片, 并返回进度值
- 递归生成数字解决问题系列
- Log4j最佳实践
- Java多线程下载实现
- Spring AOP学习笔记(4):AOP切面优先级&切面表达式重用&xml配置方式
- python ConfigParser 参数化配置 学习笔记