Remove 9 — LeetCode 660 Python Solution
HardLeetCode PremiumMath
- Problem
- #660
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The 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, ...].
Example
- Input
- n = 9
- Output
- 10
Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) or O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 660. Remove 9 is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 660. Remove 9?
- LeetCode 660. Remove 9 is rated Hard on LeetCode.
- What topics does LeetCode 660. Remove 9 cover?
- LeetCode 660. Remove 9 is tagged Math on LeetCode.
- Is LeetCode 660. Remove 9 a premium problem?
- Yes. LeetCode 660. Remove 9 is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.