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. jquery滚动条插件nanoscroller的应用

    默认的滚动条的样式,各个版本的兼容性不是很好, 推荐一款jQuery 插件nanoscroller ,可以自定义滚动条的样式. 应用: 1.引入样式 nanoscroller.css <link ...

  2. WCF和Socket

    WCF的全称是:Windows Communication Foundation.它是建立在Web Service架构上的一个全新的通信平台.它使用相同的基础结构和 API 来创建应用程序,这些应用程 ...

  3. Struts2 中#、@、%和$符号的用途

    一.#符号的用途一般有三种. “#”主要有三种用途: 1. 访问OGNL上下文和Action上下文,#相当于ActionContext.getContext():下表有几个ActionContext中 ...

  4. go语言基础之基础数据类型 bool类型 浮点型

    1.bool类型 示例1: package main import "fmt" func main() { var a bool a = true fmt.Println(&quo ...

  5. 使用Fabric模块实现自动化运维

    一.安装软件 简介:Fabric是基于Python实现的SSH命令行工具,简化了SSH的应用程序部署及系统管理任务,它提供了系统基础的操作组件,可以实现本地或远程shell命令,包括:命令执行.文件上 ...

  6. Linux now!--网络配置

    第一种:使用命令修改(直接即时生效,重启失效) #ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up 说明: eth0是第一个网卡,其他依次为eth1 ...

  7. 教你用webgl快速创建一个小世界

    收录待用,修改转载已取得腾讯云授权 作者:TAT.vorshen Webgl的魅力在于可以创造一个自己的3D世界,但相比较canvas2D来说,除了物体的移动旋转变换完全依赖矩阵增加了复杂度,就连生成 ...

  8. bash: hadoop:command not found

    这种情况应该是hadoop的bin环境变量没有配置好 打开 gedit ~/.bashrc 修改 export HADOOP_HOME=/home/hadoop1/softwares/hadoop- ...

  9. 【笔记】探索js 的this 对象 (第二部分)

    了解this 对象之后 我们明白了this 对象就是指向调用函数的作用域 那么接下来我们便要清除函数究竟在哪个作用域调用 找到调用的作用域首先要了解一下几点: 1.调用栈: 调用栈就是一系列的函数,表 ...

  10. ini配置文件的读取

    .ini 文件是Initialization File的缩写,即初始化文件.是windows的系统配置文件所采用的存储格式,统管windows的各项配置,一般用户就用windows提供的各项图形化管理 ...