lintcode 3:统计数字
来源:互联网 发布:blct升级数据 编辑:程序博客网 时间:2024/05/21 04:43
题目描述
计算数字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)
直接循环遍历每个数的每一位即可
代码
public static int digitCounts(int k, int n) { // write your code here int res = 0; while(n>=0){ int temp = n; while (temp>0){ if(temp%10==k){ res++; } temp/=10; } n--; } if (k==0){ return res+1; } return res; }
阅读全文
0 0
- lintcode-3-统计数字
- LintCode 3 统计数字
- LintCode 3 统计数字
- LintCode-(3)统计数字
- LintCode之3 统计数字
- Lintcode 3统计数字
- lintcode 3:统计数字
- LintCode-剑指Offer-(3)统计数字
- (lintcode)第3题统计数字
- Lintcode : 统计数字
- lintcode ----统计数字
- LintCode Python 统计数字
- [LintCode]3.统计数字
- LintCode 3.统计数字
- Lintcode 3. 统计数字
- lintcode&九章算法——No.3 统计数字 ? 待解决
- LintCode笔记(7)——统计数字
- 【LintCode】3.统计数字(Medium)解题报告
- make 命令的自动推导功能
- PHP入门-运算符与操作符
- 1079. 延迟的回文数 (20)
- Android实现掌盟战绩图(矩形进度条)
- 解决Redis服务错误一例听语音
- lintcode 3:统计数字
- Android中TextView实现富文本展示效果
- java
- 理解node中的require和exports
- coursera Machine Learning 第六周 测验quiz2答案解析 Machine Learning System Design
- 快速幂取模
- java大数据
- PHP入门-变量声明与使用
- 新老系统迁移及整合方案