LeetCode 660: Remove 9 Solution

Master LeetCode problem 660 (Remove 9), a hard challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

660. Remove 9

Hard

Problem Explanation

Explanation:

This problem asks us to remove all occurrences of the digit 9 from the numbers starting from 1 and concatenate them in increasing order. We need to return the n-th integer after removing all occurrences of the digit 9.

To solve the problem, we can use a base-9 number system. By representing the numbers in base-9 and mapping the digit 9 to 10, we can easily calculate the n-th number without having to generate all numbers up to n.

Algorithmic Steps:

  1. Convert the input n to base-9 representation by mapping digit 9 to 10.
  2. Calculate the n-th number in base-9 representation.
  3. Convert the n-th number back to decimal representation.

Time Complexity: O(log(n))
Space Complexity: O(1)

: :

Solution Code

class Solution {
    public int newInteger(int n) {
        return Integer.parseInt(Integer.toString(n, 9));
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 660 (Remove 9)?

This page provides optimized solutions for LeetCode problem 660 (Remove 9) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 660 (Remove 9)?

The time complexity for LeetCode 660 (Remove 9) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 660 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 660 in Java, C++, or Python.

Back to LeetCode Solutions