is there any one rememeber there is a leetcode question about how to calculate how many number which contains like number #7?
what if remove number 7?


@roc571 Could you help me understand why remove 7 is the same? The remaining numbers are different, they are not 7based numbers.

@knightzf removing any number is still 9base. Instead of using 08, you need to use 09 without the special number. Therefore, remapping would be easy way.

@roc571 said in what if remove number 7?:
I think remove 7 is same as remove 9 with mapping 7>8, 8>9. For example, you get answer as 18317 and the final answer would be 19318.
This isn't same as remove 9. Here we are dealing with remainders and number space can shrink from ends alone. You can not create holes and later map the digits, they've value and play role in determining the final value.

@roc571 said in what if remove number 7?:
I think remove 7 is same as remove 9 with mapping 7>8, 8>9. For example, you get answer as 18317 and the final answer would be 19318.
It is correct. Written in C++ and tested for [1, 1000].
int helper(int n) { int ans = 0, base = 1; while(n != 0) { int rem = n % 9; n /= 9; if(rem >= 7) rem++; ans = ans + rem * base; base *= 10; } return ans; } int main(int argc, const char * argv[]) { // insert code here... for(int i = 1; i <= 1000; i++) cout << i << " " << helper(i) << endl; return 0; }

As long as we just remove one number, the answer will always be similar to remove 9, but we need to remap the numbers after the removed one. For instance, after removing 7, then 8 will "be considered as 7", "9 considered as 8".
Thus, for remove 9, a streak like
...15,16,17,18,20...
will just be transformed to
...15,16,18,19,20...