LintCode-剑指Offer-(371)用递归打印数字
2015-11-21 22:48
344 查看
class Solution { public: /** * @param n: An integer. * return : An array storing 1 to the largest number with n digits. */ vector<int> numbersByRecursion(int n) { //我感觉这道题有点显得蛋疼,有可能是我没有理解。 vector<int>num; getNumWithRecursion(num,1,n); return num; } long long getNum(int n){ int tmp=1; for(int i=0;i<n;i++){ tmp=tmp*10; } return tmp; } void getNumWithRecursion(vector<int>& num,int n,int maxn){ if(n>maxn)return; static int i=1; int tmp=getNum(n); while(i/getNum(n)<1){ num.push_back(i); i++; } getNumWithRecursion(num,n+1,maxn); } };
相关文章推荐
- JSON解析 GSON解析
- JavaScript学习之路03_字符串和数组
- leetcode remove Nth Node from End python
- Bootstrap 网格系统(Grid System)
- web前端与移动开发---html标签的学习及特殊符号
- LintCode-剑指Offer-(165)合并两个排序链表
- 读bootstrap2.3.2有感1
- 小议jQuery插件开发
- JavaScript 之事件处理详解
- 在Jquery实现Ajax和JS实现Ajax的方法
- 理解 JavaScript 的作用域链
- 小议jQuery插件开发
- js中this和that
- 国内的Jquery CDN免费服务
- html5多出来的字自动隐藏并显示...
- js初学
- 18 款超酷的 HTML5 和 JavaScript 游戏引擎库
- EXTJS 6 新特性(译文)
- angular的基础知识
- AngularJS 入门学习