โจทย์
ดูฉบับแปลAt 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.
เงื่อนไข
1 ≤ n ≤ 1,000,000. Subtracting zero is not a useful move and is excluded.
ตัวอย่าง
อินพุต:
n = 14
ผลลัพธ์ที่คาดหวัง:
expected = 3
อินพุต:
long long n = 14;
ผลลัพธ์ที่คาดหวัง:
long long expected = 3;
อินพุต:
long n = 14;
ผลลัพธ์ที่คาดหวัง:
long expected = 3;
คำอธิบาย
14 → 10 → 9 → 0 uses three steps. Neither possible first subtraction can reach zero in only two steps.
อินพุต:
n = 7
ผลลัพธ์ที่คาดหวัง:
expected = 1
อินพุต:
long long n = 7;
ผลลัพธ์ที่คาดหวัง:
long long expected = 1;
อินพุต:
long n = 7;
ผลลัพธ์ที่คาดหวัง:
long expected = 1;
คำอธิบาย
Subtract the only digit, 7, to reach 0 immediately.
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน