[LintCode]3.统计数字
来源:互联网 发布:淘宝网店转让出售 编辑:程序博客网 时间:2024/05/22 10:40
计算数字k在0到n中的出现的次数,k可能是0~9的一个值
样例
例如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 {public: /* * param k : As description. * param n : As description. * return: How many k's between 0 and n. */ int digitCounts(int k, int n) { int count=0; for(int i=0;i<=n;i++) { int number=i; while(number >= 10) //number>= 10 { if(number%10 == k){ count++; } number = number/10; } if(number == k) //number0~9 count++; } return count; }};
阅读全文
0 0
- [LintCode]3.统计数字
- LintCode 3.统计数字
- Lintcode 3. 统计数字
- Lintcode : 统计数字
- lintcode ----统计数字
- 【LintCode】3.统计数字(Medium)解题报告
- lintcode 3. 统计数字 纯数学解法
- lintcode-3-统计数字
- LintCode 3 统计数字
- LintCode 3 统计数字
- LintCode Python 统计数字
- LintCode-(3)统计数字
- LintCode之3 统计数字
- Lintcode 3统计数字
- lintcode 3:统计数字
- LintCode-剑指Offer-(3)统计数字
- (lintcode)第3题统计数字
- LintCode笔记(7)——统计数字
- 如何设计出MySQL高性能表
- [POJ 1062] 昂贵的聘礼 [最短路+枚举] [dijkstra]
- Python对内存的使用(深拷贝和浅拷贝)
- <音频编解码>
- Java面试题2:多线程与synchronized
- [LintCode]3.统计数字
- 添加Tab Control控件
- Python函数中的参数传递
- dwz Error loading XML document: dwz.frag.xml Http status: 200 OK
- Linux 搭建 YUM 服务器
- HDU_6153 A Secret【扩展KMP】
- CentOS6.5环境下MySQL编译安装
- github项目托管
- 模型融合