Problem
Übersetzung anzeigenAt each step, choose a nonzero decimal digit currently present in the number and subtract that digit. Digits are taken from the new value after every step. Find the minimum number of steps needed to reach zero.
Implement removing_digits(n).
Input
n: The positive starting number.
Output
Return the fewest subtraction steps.
Einschränkungen
1 ≤ n ≤ 1,000,000. Subtracting zero is not a useful move and is excluded.
Beispiele
Eingabe:
n = 14
Erwartete Ausgabe:
expected = 3
Eingabe:
long long n = 14;
Erwartete Ausgabe:
long long expected = 3;
Eingabe:
long n = 14;
Erwartete Ausgabe:
long expected = 3;
Erläuterung
14 → 10 → 9 → 0 uses three steps. Neither possible first subtraction can reach zero in only two steps.
Eingabe:
n = 7
Erwartete Ausgabe:
expected = 1
Eingabe:
long long n = 7;
Erwartete Ausgabe:
long long expected = 1;
Eingabe:
long n = 7;
Erwartete Ausgabe:
long expected = 1;
Erläuterung
Subtract the only digit, 7, to reach 0 immediately.
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.