- 转换成字符串进行统计
public class Solution {
public int NumberOf1Between1AndN_Solution(int n) {
int total=0;
for(int i=1;i<=n;i++)
{
int len1=Integer.toString(i).length();
String a=Integer.toString(i);
for(int j=0;j<len1;j++)
{
if(a.charAt(j)=='1')
{
total++;
}
}
}
return total;
}
}