problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
lintcode::digit_counts::Solution类 参考

#include <lintcode.h>

静态 Public 成员函数

static int digitCounts (int k, int n)
 

详细描述

在文件 lintcode.h141 行定义.

成员函数说明

◆ digitCounts()

int lintcode::digit_counts::Solution::digitCounts ( int  k,
int  n 
)
static
参数
kAn integer
nAn integer
返回
: An integer denote the count of digit k in 1..n

在文件 lintcode.cpp279 行定义.

279 {
280 int count = 0;
281 for(int i = 0; i <= n; i++) {
282 int cpy = i;
283 while(cpy != 0) {
284 if(cpy % 10 == k) {
285 count++;
286 }
287 cpy /= 10;
288 }
289 }
290 if(k == 0) {
291 count++;
292 }
293 return count;
294 }

被这些函数引用 lintcode::digit_counts::TEST().


该类的文档由以下文件生成: