#Calculate String Rotation
Write a function that receives two strings and returns n, where n is equal to the number of characters we should shift the first string forward to match the second.
For instance, take the strings "fatigue" and "tiguefa". In this case, the first string has been rotated 5 characters forward to produce the second string, so 5 would be returned.
If the second string isn't a valid rotation of the first string, the method returns -1.
Examples:
"coffee", "eecoff" => 2
"eecoff", "coffee" => 4
"moose", "Moose" => -1
"isn't", "'tisn" => 2
"Esham", "Esham" => 0
"dog", "god" => -1
'매일매일개발 > Codewars' 카테고리의 다른 글
Codewars #8 Middle Permutation (4kyu) (0) | 2018.03.26 |
---|---|
Codewars #7 Josephus Permutation (5kuy) (0) | 2018.03.25 |
Codewars #5 Take a Number And Sum Its Digits Raised To The Consecutive Powers And ....¡Eureka!! (6kuy) (0) | 2018.03.23 |
Codwars #4 Find the unique number (6kyu) (0) | 2018.03.22 |
Codwars #3 Sort the odd (6kyu) (0) | 2018.03.21 |