LintCode之3 统计数字
来源:互联网 发布:淘宝助理如何图片搬家 编辑:程序博客网 时间:2024/05/22 01:34
题目来源:统计数字
题目描述:
计算数字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)
Java代码:
public int digitCounts(int k, int n) { // write your code here int number = 0,count=0,c=0; for(int i=0;i<=n;i++) { number = i; while(number>0) { c=number; if(c==k) count++; number=number/10; } } if(k==0) count++; return count; }
阅读全文
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)解题报告
- 通过目标程序名字获取进程PID
- RegExp 正则表达式的方法
- TCP协议详解
- 入门
- 3、spring-boot访问数据库
- LintCode之3 统计数字
- activity简介
- 1.系统分盘-压缩出的空间即最大空间分配
- 图解重定向的原理
- angularJS——路由
- JavaEE 绝对路径、相对路径获取方式
- 二叉树
- FPGA之QuartusII 下载 配置 (入门篇)
- 大数据WEB阶段(七)JDBC、数据库批处理、数据库连接池