✅ Solve "Rotate String" in JavaScript | 0ms Runtime | Beats 100% 🚀

Publié le: 11 mars 2025
sur la chaîne: Networking Code
6
1

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


Sur cette page du site, vous pouvez voir la vidéo en ligne ✅ Solve "Rotate String" in JavaScript | 0ms Runtime | Beats 100% 🚀 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Networking Code 11 mars 2025, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 6 fois et il a aimé 1 téléspectateurs. Bon visionnage!