lintcode-3-统计数字
2016-08-18 10:16
405 查看
统计数字
描述
笔记
数据
评测
计算数字k在0到n中的出现的次数,k可能是0~9的一个值
您在真实的面试中是否遇到过这个题? Yes
样例
例如n=12,k=1,在 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],我们发现1出现了5次 (1, 10, 11, 12)
描述
笔记
数据
评测
计算数字k在0到n中的出现的次数,k可能是0~9的一个值
您在真实的面试中是否遇到过这个题? Yes
样例
例如n=12,k=1,在 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],我们发现1出现了5次 (1, 10, 11, 12)
class Solution { /* * param k : As description. * param n : As description. * return: An integer denote the count of digit k in 1..n */ int countnumber(int l,int k){ int lnum=0; while(l>=10){ if(k==l%10){ lnum++; } l=l/10; } if(l==k) lnum++; return lnum; } public int digitCounts(int k, int n) { // write your code here int number=0; for(int i=0;i<=n;++i){ number=number+countnumber(i,k); } return number; } };
相关文章推荐
- 日常练习:lintcode 3. 统计数字
- LintCode 3 统计数字
- LintCode之3 统计数字
- lintcode 3:统计数字
- LintCode题解之统计数字
- lintcode 3.统计数字
- lintcode&九章算法——No.3 统计数字 ? 待解决
- lintcode 3. 统计数字 纯数学解法
- lintcode--第3题:统计数字
- Lintcode 3统计数字
- LintCode Python 统计数字
- LintCode 3.统计数字
- lintcode题目-3.统计数字
- lintcode ----统计数字
- LintCode-3.统计数字
- LintCode 3 统计数字
- LintCode Remove Duplicates from Sorted Array II 删除排序数组中的重复数字 II
- lintcode 旋转数组的最小数字
- LiintCode----3.统计数字
- LintCode:整数转罗马数字