Class Solution
- java.lang.Object
-
- g1501_1600.s1540_can_convert_string_in_k_moves.Solution
-
public class Solution extends Object
1540 - Can Convert String in K Moves.Medium
Given two strings
sandt, your goal is to convertsintotinkmoves or less.During the
ith(1 <= i <= k) move you can:- Choose any index
j(1-indexed) froms, such that1 <= j <= s.lengthandjhas not been chosen in any previous move, and shift the character at that indexitimes. - Do nothing.
Shifting a character means replacing it by the next letter in the alphabet (wrapping around so that
'z'becomes'a'). Shifting a character byimeans applying the shift operationsitimes.Remember that any index
jcan be picked at most once.Return
trueif it’s possible to convertsintotin no more thankmoves, otherwise returnfalse.Example 1:
Input: s = “input”, t = “ouput”, k = 9
Output: true
Explanation: In the 6th move, we shift ‘i’ 6 times to get ‘o’. And in the 7th move we shift ‘n’ to get ‘u’.
Example 2:
Input: s = “abc”, t = “bcd”, k = 10
Output: false
Explanation: We need to shift each character in s one time to convert it into t. We can shift ‘a’ to ‘b’ during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.
Example 3:
Input: s = “aab”, t = “bbb”, k = 27
Output: true
Explanation: In the 1st move, we shift the first ‘a’ 1 time to get ‘b’. In the 27th move, we shift the second ‘a’ 27 times to get ‘b’.
Constraints:
1 <= s.length, t.length <= 10^50 <= k <= 10^9s,tcontain only lowercase English letters.
- Choose any index
-
-
Constructor Summary
Constructors Constructor Description Solution()
-