In this video, we solve LeetCode problem 796. Rotate String using JavaScript. Our solution achieves 0ms runtime and beats 100% of submissions! 🚀
🔹 Problem Statement:
Given two strings s and goal, return true if s can be transformed into goal by performing a series of left shifts (moving the leftmost character to the rightmost position).
🔹 Example:
js
Copy
Edit
Input: s = "abcde", goal = "bcdea"
Output: true
💡 Approach:
We check if goal is a rotation of s by verifying whether goal is a substring of s + s.
📌 Code Solution:
js
Copy
Edit
var rotateString = function(s, goal) {
return s.length === goal.length && (s + s).includes(goal);
};
🔹 Time Complexity: O(N)
🔹 Space Complexity: O(N)
🔥 If you found this helpful, don't forget to Like, Comment, and Subscribe! 🚀
#JavaScript #LeetCode #Coding #InterviewPrep #MERN #RotateString #DSA #Algorithms
Nesta página do site você pode assistir ao vídeo on-line ✅ Solve "Rotate String" in JavaScript | 0ms Runtime | Beats 100% 🚀 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Networking Code 11 Março 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 6 vezes e gostou 1 espectadores. Boa visualização!