public class Solution { public int NumberOf1Between1AndN_Solution(int n) { int base = 1 ; int h = n ; int l = 0 ; int cur = 0 ; int res = 0 ; while(h > 0) { h = n/base/10 ; l = n%base ; cur = n/base%10 ; if(cur == 0) { res += h * base ;//借位 } else if(cur == 1) { res += 1 * (l+1) ;//不借位 res += h * base ;//借位 } else { res += 1* base ;//不借位 res += h * base ;//借位 } base *= 10 ; } return res ; } }