Problem Statement |
| You will be given 2 numbers start and finish each with the same number of digits. Both may have leading zeros. You are going to transform start into finish using the following kinds of transformation steps:
- 1) Increment a digit less than 9 by 1. For example, changing 354 to 364.
- 2) Decrement a digit greater than 0 by 1. For example, changing 354 to 254.
- 3) Swapping two digits. For example, changing 354 to 453.
Return the fewest number of transformation steps required to change start into finish. |
|
Definition |
| Class: | NumberChanger | Method: | transform | Parameters: | String, String | Returns: | int | Method signature: | int transform(String start, String finish) | (be sure your method is public) |
|
|
|
|
Constraints |
- | start will contain between 1 and 8 characters inclusive. |
- | Each character in start will be a digit ('0'-'9'). |
- | finish will contain the same number of characters as start. |
|
Examples |
0) | |
| |
1) | |
| |
2) | |
| | Returns: 16 | Swapping is of no use here. |
|
|
3) | |
| |
4) | |
| |