参考:
[1]剑指OFFER P221 比较初级的解法,时间复杂度为nlogn
class Solution {
public:
int NumberOf1Between1AndN_Solution(int n)
{
int number = 0;
for(int i=1;i<=n;i++)
number +=NumberOf1(i);
return number;
}
int NumberOf1(int i)
{
int number = 0;
while(i)
{
if(i%10 ==1)
number++;
i = i/10;
}
return number;
}
};