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