Problem Statement
给定一个字符串,然后给定一个目标串,
每一次可以讲所有的相同字符+1或者-1,其中z+1=a
给定+1的代价和-1的代价,然后你要计算出最小的代价。
Consider a string consisting of lowercase characters and following two operations that can change it:
- Next: Choose a lowercase character and replace its every occurrence with the next character.
The next character of 'z' is 'a' ('a' -> 'b', 'b' -> 'c', ..., 'y' -> 'z', 'z' -> 'a').
- Prev: Choose a lowercase character and replace its every occurrence with the previous character.
The previous character of 'a' is 'z' ('a' -> 'z', 'b' -> 'a', ..., 'y' -> 'x', 'z' -> 'y').
You can use each operation as many times as you want, and in any order you like.
You are given ints nextCost and prevCost.
These represent the cost of using each Next and Prev operation, respectively.
You are also given two Strings start and goal.
Return the minimum cost required in order to transform start into goal using the above operations.
If transforming start into goal is impossible, return -1 instead.