lintcode-medium-Digit Counts
Posted 哥布林工程师
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lintcode-medium-Digit Counts相关的知识,希望对你有一定的参考价值。
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 { /* * param k : As description. * param n : As description. * return: An integer denote the count of digit k in 1..n */ public int digitCounts(int k, int n) { // write your code here int count = 0; for(int i = k ; i <= n; i++){ count += singleCount(i, k); } return count; } public int singleCount(int num, int k){ if(num == 0 && k == 0) return 1; int count = 0; while(num > 0){ if(num % 10 == k) count++; num /= 10; } return count; } };
以上是关于lintcode-medium-Digit Counts的主要内容,如果未能解决你的问题,请参考以下文章
http_request_duration_seconds_sum / http_request_duration_seconds_count 显示 2 个图表