public int NumberOf1Between1AndN_Solution(int n) {

        int base = 1;
        int res = 0;
        while(base <= n){
            int b = n%base;
            int a = n/base;
            int cur = a%10;
            a = a/10;
            if(cur > 1)
                res += (a+1)*base;
            else if(cur == 0)
                res += a*base;
            else res += a*base+b+1;
            base *= 10;
        }
        return res;
    }