public class Solution {
    public int NumberOf1Between1AndN_Solution(int n) {
        int digit = 1;
        int cur = n % 10;
        int high = n / 10;
        int low = 0;
        int count = 0;
        while (n !=  low) {
            if (cur == 0) {
                count += (high * digit);
            } else if (cur == 1) {
                count += (high * digit + low + 1);
            } else {
                count += ((high + 1) * digit);
            }
            low += cur * digit;
            cur = high % 10;
            high = high / 10;
            digit *= 10;
        }
        return count;
    }
}