660. Remove 9

LeetCode hard original: C# #csharp #hard #leetcode #search #string
El texto de la tarea se traduce del ruso para el idioma seleccionado. El código no cambia.

Начните с целого числа 1, уберите любое number, которое содержит 9, такое как 9, 19, 29...

Теперь у вас будет новая последовательность целых чисел [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...].

given entero n, return n-е (начиная с 1) entero в новой последовательности.

Ejemplo

Input: n = 9

Output: 10

C# solución

coincidente/original
public class Solution {
    public int NewInteger(int n) {
        int count = 0;
        int num = 0;
        while (count < n) {
            num++;
            if (!num.ToString().Contains("9")) {
                count++;
            }
        }
        return num;
    }
}

C++ solución

borrador automático, revisar antes de enviar
#include <bits/stdc++.h>
using namespace std;

// Auto-generated C++ draft from the C# solution. Review containers, LINQ and helper types before submit.
class Solution {
public:
    public int NewInteger(int n) {
        int count = 0;
        int num = 0;
        while (count < n) {
            num++;
            if (!num.ToString().Contains("9")) {
                count++;
            }
        }
        return num;
    }
}

Java solución

coincidente/original
public class Solution {
    public int newInteger(int n) {
        int count = 0;
        int num = 0;
        while (count < n) {
            num++;
            if (!Integer.toString(num).contains("9")) {
                count++;
            }
        }
        return num;
    }
}

Algorithm

Инициализация:

Начните с числа 1 и создайте переменную для отслеживания количества найденных чисел, не содержащих цифру 9.

Итерация и проверка:

Последовательно увеличивайте number и проверяйте, содержит ли оно цифру 9.

Если не содержит, увеличьте счетчик.

Поиск n-го числа:

Продолжайте процесс до тех пор, пока не найдете n-е number, не содержащее цифру 9.

😎

Vacantes para esta tarea

Se muestran vacantes activas con etiquetas coincidentes.

Todas las vacantes
Todavía no hay vacantes activas.