Count the number of k's between 0 and n. k 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)

解法一:

 class Solution {
public:
// param k : description of k
// param n : description of n
// return ans a integer
int digitCounts(int k, int n) {
int count = ;
if (k == ) {
count = ;
}
for (int i = ; i <= n; i++) {
int number = i;
while (number > ) {
if (number % == k) {
count += ;
}
number /= ;
}
} return count;
}
};

3. Digit Counts【medium】的更多相关文章

  1. 2. Add Two Numbers【medium】

    2. Add Two Numbers[medium] You are given two non-empty linked lists representing two non-negative in ...

  2. 92. Reverse Linked List II【Medium】

    92. Reverse Linked List II[Medium] Reverse a linked list from position m to n. Do it in-place and in ...

  3. 82. Remove Duplicates from Sorted List II【Medium】

    82. Remove Duplicates from Sorted List II[Medium] Given a sorted linked list, delete all nodes that ...

  4. 61. Search for a Range【medium】

    61. Search for a Range[medium] Given a sorted array of n integers, find the starting and ending posi ...

  5. 62. Search in Rotated Sorted Array【medium】

    62. Search in Rotated Sorted Array[medium] Suppose a sorted array is rotated at some pivot unknown t ...

  6. 74. First Bad Version 【medium】

    74. First Bad Version [medium] The code base version is an integer start from 1 to n. One day, someo ...

  7. 75. Find Peak Element 【medium】

    75. Find Peak Element [medium] There is an integer array which has the following features: The numbe ...

  8. 159. Find Minimum in Rotated Sorted Array 【medium】

    159. Find Minimum in Rotated Sorted Array [medium] Suppose a sorted array is rotated at some pivot u ...

  9. Java for LeetCode 207 Course Schedule【Medium】

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

随机推荐

  1. alert和console的区别

    前端开发调试中用的最多的两个命令就是console和alert了吧,做了两年前端了,发现好多人连这两个命令的区别都还不清楚,今天正好没什么事情做,于是按照自己的理解随便说说.   alert: 1.会 ...

  2. LINUX提权后获取敏感信息之方法

    文中的每行为一条命令,文中有的命令可能在你的主机上敲不出来,因为它可能是在其他版本的linux中所使用的命令. 列举关键点 (Linux)的提权是怎么一回事:  收集 – 枚举,枚举和一些更多的枚举. ...

  3. WINXP上安装及使用SqlMap之方法

    1.首先下载SqlMap 点击下载.2.其次下载用于Windows系统的Python ……点击这里…… 3.然后安装Python:Python默认安装的路径是“C:\Python”(你也可以修改安装路 ...

  4. asset bundle打包策略

    一次引用的 不单独打包 2次的看大小 小的不单独打包 2次以上单独打包 2这个值 可以测一测 取平衡

  5. Jquery事件冒泡

    事件冒泡 什么是事件冒泡 在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么 ...

  6. 【实践】用for-in 循环实现三联联动

    之前用jq 做过一次三联联动以及四联联动 现在为了更好地了解对象用js的原生方式做了一次 *本节要点方法:  obj.selectedIndex  获取下拉列表选中的option 的索引  obj.o ...

  7. Java线程详细监控和其dump的分析使用—-分析Java性能瓶颈

    转载:https://www.cnblogs.com/firstdream/p/8109352.html 这里对linux下.sun(oracle) JDK的线程资源占用问题的查找步骤做一个小结: l ...

  8. 在笛卡尔坐标系上描绘函数(x*x+1)/(x*x-1)曲线

    代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type ...

  9. Android NDK 交叉编译C++代码生成.so共享库详细步骤

    Android NDK 交叉编译C++代码生成.so共享库详细步骤 Android NDK 调用c++ stl 模板库(修改android.mk文件) 1  在需要调用模板库的文件前包含头文件:   ...

  10. windows下流媒体nginx-rmtp-module服务器搭建及java程序调用fmpeg将rtsp转rtmp直播流【转】

    https://github.com/illuspas/nginx-rtmp-win32 http://bashell.sinaapp.com/archives/build-nginx-rtmp-mo ...