原题:
假如给n为9,那么输出为1,因为1~9中1出现一次。
假如给n为11,那么输出4,因为1~11中1出现4次(1,10,11)
class GetCount{
public static int solution(int n){
int high = n/10,low =0,digit = 1,cur=n%10;
int res = 0;
while (high!=0||cur!=0){
if (cur == 0) res+=high*digit;
else if (cur ==1) res += high*digit+low+1;
else res += (high + 1) * digit;
cur=high%10;
low += cur*digit;
digit *=10;
high/=10;
}
return res;
}
}