> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Remove 9 Python Solution with Tests

> Tested Python solution for LeetCode 660 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 660, [Hard](/catalog/hard). Topics: [Math](/catalog/topics/math). [View on LeetCode](https://leetcode.com/problems/remove-9/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 660   # by problem number
lcpy gen -s remove_9   # by problem name
```

## Problem

Start from integer `1`, remove any integer that contains `9` such as `9`, `19`, `29`...

Now, you will have a new integer sequence `[1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...]`.

Given an integer `n`, return *the* `n^th` (**1-indexed**) integer in the new sequence.

### Examples

```
Input: n = 9
Output: 10
```

```
Input: n = 10
Output: 11
```

### Constraints

* 1 \<= n \<= 8 \* 10^8

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_9/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/remove_9/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(log n)
    # Space: O(log n)
    def new_integer(self, n: int) -> int:
        result = 0
        place = 1
        while n > 0:
            result += (n % 9) * place
            place *= 10
            n //= 9
        return result
```

## Complexity

| Time | Space |
| - | - |
| O(log n) | O(log n) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.