lintcode:Digit Counts
来源:互联网 发布:淘宝苏宁买手机可靠吗 编辑:程序博客网 时间:2024/05/15 10:03
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 FIVE1's (1, 10, 11, 12)
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 result = 0; int base = 1; while (n/base > 0) { int cur = (n/base)%10; int low = n-(n/base) * base;; int high = n/(base * 10); if (cur < k) { result += high*base; } else if (cur > k) { result += (high+1)*base; } else { result += high*base+low+1; } base *= 10; } return result; }};
0 0
- lintcode:Digit Counts
- **[Lintcode]Digit Counts
- Lintcode 3:Digit Counts
- digit-counts
- #3 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
- Digit Divide Numbers-LintCode
- LINTCODE——Digit Divide Numbers
- LintCode
- lintcode--
- lintcode
- LintCode
- Lintcode
- Struts1.2中ActionForm的理解
- web服务器和应用服务器概念比较
- 面试题19二叉树的镜像
- nginx信号量
- 深度探究this指针以及空的结构体或者类
- lintcode:Digit Counts
- SQLServer数据库中获取每月第一天和最后天的方法以及扩展
- apache hadoop-2.6.0-CDH5.4.1 安装笔记
- Linux下查看端口号
- leetcode--Sort Colors
- 利用Excel查找替换Word文本框里的内容
- CMake常见指令总结,修改的更加容易理解
- NLog的资料
- 探究单向链表逆置转向及检查成环的问题