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. 【java】LIst切割----划分 List为几个LIst的几种工具类 1.按照目标份数划分 2.按照目标容量划分 【适用场景:mybatis分批次In查询,放置In拼接sql过长】

    如题,示例代码如下: /** * 1> 按照份数---划分list * @param source * @param num 想要划分成多少份 * @return */ public stati ...

  2. (转)HBase 常用Shell命令

    转自:http://my.oschina.net/u/189445/blog/595232 hbase shell命令                             描述  alter 修改 ...

  3. 如何访问python类中的私有方法

    在python中,不像c#/java类语言,支持类的私有方法,这点有点像objc,虽然objc可以通过扩展extension来实现,但源于objc的运行时特性,我们还是可以通过非常手段来进行访问的.不 ...

  4. Linux下libsvm的安装及简单练习

    引文:常常在看paper的时候.就看到svm算法,可是要自己来写真的是难于上青天呀! 所幸有一个libsvm的集成软件包给我们使用,这真的是太好了.以下简介下怎么来使用它吧! LIBSVM是一个集成软 ...

  5. v - on

    1. v-on绑定:on:click点击事件,再触发方法里面的add()或del() 2. 详情查看官方文档:https://cn.vuejs.org/v2/api/#v-on <!DOCTYP ...

  6. vue - .postcssrc.js

    描述:添加浏览器私缀(私缀是上世纪90年代浏览器大战的产物,也是现在新型浏览器支持某些新API,而其它浏览器不支持的证明!) 我们看看App.vue 再来看看打包后的css文件 一切都是靠你postc ...

  7. github 管理图示

  8. DNS使用的是TCP协议还是UDP协议简析

    DNS使用的是TCP协议还是UDP协议简析   DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况 ...

  9. Android Exception 7(attempt to re-open an already-closed object )

    07-23 18:16:17.641: W/SQLiteConnectionPool(28390): A SQLiteConnection object for database '/storage/ ...

  10. IOS Exception 1(RangeText="[SKTexture]()")

    CompileSwift normal x86_64 com.apple.xcode.tools.swift.compiler cd /Users/Rubert/workspaces/Panda ex ...