LintCode 用递归打印数字
来源:互联网 发布:js indexof 用法 编辑:程序博客网 时间:2024/05/29 03:18
中等 用递归打印数字
24%
通过
用递归的方法找到从1到最大的N位整数。
您在真实的面试中是否遇到过这个题?Yes
样例
给出 N = 1
, 返回[1,2,3,4,5,6,7,8,9]
.
给出 N = 2
, 返回[1,2,3,4,5,6,7,8,9,10,11,...,99]
.
用字符串模拟数字
class Solution {public: /** * @param n: An integer. * return : An array storing 1 to the largest number with n digits. */ vector<int> numbersByRecursion(int n) { // write your code here vector<int> res; if (n ==0) { return res; } char *num = new char[n+1]; num[n] = '\0'; for (int i = 0; i < 10; ++i) { num[0] = i + '0'; recursion(num,n,0,res); } delete [] num; return res; } void recursion(char * num,int length,int index,vector<int>& res) { if (index == length-1) { int a = atoi(num); if(a != 0) { res.push_back(a); } return; } for (int i=0; i< 10; i++) { num[index + 1] = i +'0'; recursion(num,length, index+1 ,res); } return; }};
0 0
- LintCode-用递归打印数字
- LintCode 用递归打印数字
- lintcode-用递归打印数字
- Lintcode 用递归打印数字
- LintCode 用递归打印数字
- 用递归打印数字-LintCode
- lintcode(371)用递归打印数字
- [LintCode]371.用递归打印数字
- LintCode-剑指Offer-(371)用递归打印数字
- [LintCode] 用递归打印数字 Print Numbers by Recursion
- 用递归打印数字
- 用递归打印数字
- 递归打印数字
- 【递归】数字打印
- 递归打印螺旋数字
- Lintcode 用递归打印从1到N位的最大整数
- 0021利用递归算法打印数字金字塔
- 蓝桥杯常用算法知识点:【递归】数字打印
- 二维码扫描实现
- Android studio开发环境下载安装
- 【c语言】实现一个函数,求字符串的长度,不允许创建第三方变量
- linux内核 asmlinkage宏
- zendframework源码浅析之Zend_Loader
- LintCode 用递归打印数字
- 分布式消息发布订阅消息系统Kafka
- 【c语言】模拟实现库函数strcpy函数
- java总结之 : ++i和i++的区别
- fwrite 返回值是实参count的写入个数
- Android百度地图导航部分报JNI相关错误
- ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the cont
- Excel 中列出所有满足条件的项
- 40 个超棒的免费 Bootstrap HTML5 网站模板