Remove 9

hard math

Problem

If you list non-negative integers and remove any containing the digit 9, return the n-th remaining.

Inputn = 9
Output10
Skip 9; the 9th surviving number is 10.

def new_integer(n):
    out = 0; place = 1
    while n:
        out += (n % 9) * place; n //= 9; place *= 10
    return out
function newInteger(n) {
  let out = 0, place = 1;
  while (n) { out += (n % 9) * place; n = Math.floor(n / 9); place *= 10; }
  return out;
}
int newInteger(int n) {
    int out = 0, place = 1;
    while (n > 0) { out += (n % 9) * place; n /= 9; place *= 10; }
    return out;
}
int newInteger(int n) {
    int out = 0, place = 1;
    while (n > 0) { out += (n % 9) * place; n /= 9; place *= 10; }
    return out;
}
Time: O(log n) Space: O(1)