3. Digit Counts【medium】
Count the number of k's between 0 and n. k can be 0 - 9.
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】的更多相关文章
- 2. Add Two Numbers【medium】
2. Add Two Numbers[medium] You are given two non-empty linked lists representing two non-negative in ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 75. Find Peak Element 【medium】
75. Find Peak Element [medium] There is an integer array which has the following features: The numbe ...
- 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 ...
- 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 ...
随机推荐
- jQuery:validate内置验证的使用
(1)required:true 必输字段(2)remote:"check.php" 使用ajax方法调用check.php验证输入值(3)email:true 必须输入正确格式的 ...
- 关于如何避免Android中Bitmap引起的OutOfMemoryError
在Android中处理大图片不是一件很随意的事情,因为通常我们使用的是内置的BitmapFactory解码图片的,而BitmapFactory往往会因为图片过大而遇到OutOfMemoryError的 ...
- extern用法
Extern用法 用例子给你示范 // 1.cpp ; // 2.cpp 注意没有包含1.cpp #include <iostream> using namespace std; exte ...
- 如何破解linux用户帐号密码一
ENCRYPT_METHOD SHA512 定义帐号密码的加密方式 1.第一步拿到散列,也就是加密后的密码hash值 2.可以去一些彩虹表(rainbow)网站查询这些hash对应的密码明文,稍微花些 ...
- http://blog.csdn.net/congcong68/article/details/39256307
http://blog.csdn.net/congcong68/article/details/39256307
- UVa 164 - String Computer
题目:编辑距离.给你两个串,将已知串转化成目标串,能够增.删.改字母,求最小操作次数. 分析:dp,编辑距离.同最大公共子序列. 注意操作位置是实时变化的. (前面都已经处理好了) ...
- 【云计算】Docker多进程管理方案-cfengine && supervisord
docker容器内多进程的管理方案 时间 2015-05-08 00:00:00 涯余 原文 http://yayua.github.io/docker/container-process-moni ...
- android 步骤控件的使用
有的时候我们做Android开发会用到表示步骤的需求.这时候github给我们提供了一个非常好地表示步骤的组件,使用她仅仅须要4步就能够完毕了. 项目地址https://github.com/anto ...
- Thinkpad 笔记本 装win7 64 位操作系统热键驱动装不上问题解决!
Thinkpad 笔记本 装win7 64 位操作系统热键驱动装不上问题解决! 一般牛人的解释如下: 问题终于搞定.是因为需要手工建%PROGRAMFILES%\Lenovo\Hotkey目录.这个写 ...
- git 批量删除文件夹和文件
git 批量删除文件夹和文件 硬盘删除文件后,执行$ git status 会提示你仍然需要$ git rm <文件> 此时如果是要删除大批量文件,这么一个一个命令下去不得累死人啊 ...