Count the number of k's between 0 and nk can be 0 - 9.

Example

if n = 12, k = 1 in

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

we have FIVE 1's (1, 10, 11, 12)

分析:

利用while 循环 + num % 10可以获取 num中的所有数字。

class Solution {
/*
* param k : As description.
* param n : As description.
* return: An integer denote the count of digit k in 1..n
*/
public int digitCounts(int k, int n) {
int totalCount = ;
for (int i = ; i <= n; i++) {
totalCount += counts(k, i);
}
return totalCount;
} public int counts(int k, int value) {
int count = ;
if (value == && k == ) return ;
while (value != ) {
int remainder = value % ;
if (remainder == k) {
count++;
}
value = value / ;
}
return count;
}
};

最新文章

  1. source /etc/profile报错-bash: id:command is not found
  2. hibernate的一种报错
  3. 刚看到的感觉会用的到 收藏一下 常用的iOS第三方资源 (转)
  4. 关于SCRUM站立会议
  5. js实现对数据库的增删查改
  6. 使用GDI+轻松创建缩略图
  7. EasyUI的下拉选择框控件方法被屏蔽处理方式
  8. 插件式Web框架
  9. Chrome调试大全
  10. 【Spring 核心】AOP 面向切面编程
  11. springBoot系列教程03:redis的集成及使用
  12. nodejs http小爬虫
  13. 初识 go 语言
  14. advanceskeleton插件分身体和表情单独绑定的时候合并表情步骤
  15. NAT详解:基本原理、穿越技术(P2P打洞)、端口老化等
  16. ssh登陆报错:packet_write_wait: Connection to x.x.x.x port 22: Broken pipe
  17. 检查mono兼容性的工具MOAM
  18. php中正则表达式的语法规则
  19. 廖雪峰老师Python教程读后笔记
  20. springboot整合thumbnailator实现图片压缩

热门文章

  1. struts的上传和下载
  2. 利用css3实现超出文本指定行数与省略号效果
  3. 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor
  4. Java编程思想学习(二) 操作符
  5. Linux Process/Thread Creation、Linux Process Principle、sys_fork、sys_execve、glibc fork/execve api sourcecode
  6. RIP、OSPF、BGP、动态路由选路协议、自治域AS
  7. OracleOraDb10g_home1TNSListener无法启动
  8. 使用guava带来的方便
  9. GTP V0 和 GTP V1
  10. 基础知识系列☞Abstract和Virtual→及相关知识