#3 Digit Counts
来源:互联网 发布:私下买卖淘宝店犯法吗 编辑:程序博客网 时间:2024/06/10 00:58
题目描述:
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)
这题。。我就是死做。。遍历0~n,每个数字都算一下k出现的次数,然后加起来。。
Mycode(AC = 130ms):
class Solution {public: /* * param k : As description. * param n : As description. * return: How many k's between 0 and n. */ int digitCounts(int k, int n) { // write your code here int count = 0; for (int i = 0; i <= n; i++) { count += countHelper(to_string(i), k); } return count; } int countHelper(string num, int k) { int count = 0; for (int i = 0; i < num.size(); i++) { if (num.substr(i, 1) == to_string(k)) { count++; } } return count; }};
0 0
- #3 Digit Counts
- Lintcode 3:Digit Counts
- digit-counts
- lintcode:Digit Counts
- **[Lintcode]Digit Counts
- Digit Counts 解题报告
- Problem 63 Powerful digit counts
- Project Euler 题解 #63 Powerful digit counts
- Project Euler:Problem 63 Powerful digit counts
- 3.Digit Counts-统计数字(中等题)
- 算法学习笔记--7.digit-counts
- 1.2.3 Reference Counts(引用计数)
- STM32 Tutorial: #3 Show digit
- Adjacent Bit Counts(P3786)
- Incrementing Counts in SQL
- hdu 4486 pen counts
- Uva 6174 Pen Counts
- hdu 4486 Pen Counts
- Windows API 常用函数
- Hibernate关联映射--多对一映射
- MySQL性能优化的最佳20+条经验(3)
- 解决Genymotion出现The virtual device got no IP address
- Android动画——逐帧动画
- #3 Digit Counts
- 【Spring学习笔记七】-Spring MVC基本配置和实例
- iOS-UIDatePicker的简单使用和时间范围限制
- 读《人月神话》有感
- BeanDefinitionStoreException Failed to read candidate component class
- 1439 统计素数个数
- ubuntu下apache2开启重写模式
- java 如何判断操作系统是Linux还是Windows
- Japan