标签:
题目描述:public int CountDigitOne(int n) { if(n <= 0){ return 0; } if(n < 10){ return 1; } var result = 0; var digit = 1; var num = n; while (num > 0) { var mod = num % 10; var sign = mod > 0 ? 1 : 0; num /= 10; int a = num * digit; int b = sign * (mod == 1 ? n % digit + 1: digit); result += a + b; digit *= 10; } return result; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/48575923