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 ...
随机推荐
- 利用tempo将json数据填充到html模板
1.下载tempo 2.使用 <!DOCTYPE html> <html> <head lang="zn-ch"> <meta chars ...
- appium+python自动化48-长按(long_press)
前言 长按操作是经常会遇到的场景,通过driver可以直接调出long_press_keycode方法,但是这个方法是长按手机上某个按钮,比如长按电源键,长按home键. 长按某个元素或者长按屏幕上某 ...
- jquery-qrcode 生成和读取二维码
首先要导入jar包(生成二维码的jar和读取二维码的jar) 生成二维码: package com.imooc.qrcode; import java.awt.Color; import java.a ...
- 【LaTeX】E喵的LaTeX新手入门教程(4)图表
这里说的不是用LaTeX画图,而是插入已经画好的图片..想看画图可以把滚动条拉到底.前情回顾[LaTeX]E喵的LaTeX新手入门教程(1)准备篇 [LaTeX]E喵的LaTeX新手入门教程(2)基础 ...
- 对Storm ETL的初步思考
ETL简介 ETL,是英文 Extract-Transform-Load 的缩写,用来描述将数据从来源端经过萃取(extract).转置(transform).加载(load)至目的端的过程. ETL ...
- 关于mysql字段名和保留字冲突的问题
建了个表,有个字段起名为key,结果insert语句报错了,说是sql不对. 原因:字段key和MySQL的保留字冲突了,当mysql的字段名和保留字冲突的时候,sql语句中的字段名需要加上反引号`` ...
- http://blog.csdn.net/xingfuzhijianxia/article/details/6433918
http://blog.csdn.net/xingfuzhijianxia/article/details/6433918
- python 如何调用子文件下的模块
在python开发中,经常会出现调用子文件夹下的py模块 如上图,如果在test.py文件中,要调用meeting文件夹下面的huodongshu.py 模块, 直接在test.py 中 import ...
- Java中PriorityQueue详解
Java中PriorityQueue通过二叉小顶堆实现,可以用一棵完全二叉树表示.本文从Queue接口函数出发,结合生动的图解,深入浅出地分析PriorityQueue每个操作的具体过程和时间复杂度, ...
- 常用HTML标签的全称及描述
常用HTML标签的英文全称及简单描述 HTML标签 英文全称 中文释义 a Anchor 锚 abbr Abbreviation 缩写词 acronym Acronym 取首字母的缩写词 addr ...