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
In questa pagina del sito puoi guardare il video online ✅ Solve "Rotate String" in JavaScript | 0ms Runtime | Beats 100% 🚀 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Networking Code 11 marzo 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 6 volte e gli è piaciuto 1 spettatori. Buona visione!