https://leetcode.com/problems/rotate-string/
Solution 1
/**
* @param {string} s
* @param {string} goal
* @return {boolean}
*/
var rotateString = function (s, goal) {
if (s.length !== goal.length) {
return false;
}
let rearrangeS = s;
for (let i = 0; i < s.length; i++) {
rearrangeS = rearrangeS.slice(1) + rearrangeS.slice(0, 1);
if (rearrangeS === goal) {
return true;
}
}
return false;
};
Runtime: 64 ms, faster than 90.15% of JavaScript online submissions for Rotate String.
Memory Usage: 42 MB, less than 66.54% of JavaScript online submissions for Rotate String.