class Solution {
public:
int NumberOf1Between1AndN_Solution(int n)
{
int count = 0;//1的个数
int i = 0;
int num;
for(i = 1;i <= n;i++)
{
num = i;
while(num)
{
if(num % 10 == 1)
{
count++;
}
num = num / 10;
}
}
return count;
}
};
思路:只要注意像11,111这种you'有多个1的就好了