문제
번역본 보기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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.