Problem
Java
my solution - brute method
1 | class Solution { |
Submission Detail
- 45 / 45 test cases passed.
- Runtime: 5 ms, faster than 9.75% of Java online submissions for Rotate String.
- Memory Usage: 38.4 MB, less than 32.29% of Java online submissions for Rotate String.
trick method
© 20+ basic Algorithms Problems from Coding Interviews 19. How to check if two String is rotations of each other?
There is a simple trick to solve this problem, just concatenate the String with itself and check if the rotation exists there. You can do that by using indexOf or substring method. If the concatenated String contains rotation then given String is a rotation of former.
1 | class Solution { |
Submission Detail
- 45 / 45 test cases passed.
- Runtime: 0 ms, faster than 100.00% of Java online submissions for Rotate String.
- Memory Usage: 37.2 MB, less than 75.85% of Java online submissions for Rotate String.