LeetCode: Valid Palindrome Solution

🚀 LeetCode: Valid Palindrome The goal is to determine if a string is a palindrome, considering only alphanumeric characters and ignoring cases. 🛠️ My Approach 1. Preprocessing: Converted the entire string to lowercase to ensure the check is case-insensitive. 🔡 2. Filtering: Used a regex-based loop (/[a-z0-9]/) to strip away non-alphanumeric characters, creating a clean string of only valid characters. 🧹 3. Two-Pointer Optimization: Instead of reversing the string (which takes extra time and memory), I used two pointers starting at opposite ends. 📍 One pointer moves from the start (i), and the other from the end (j). ❌ If the characters at these positions ever mismatch, we return false immediately. 📊 Efficiency Analysis ⏱️ Time Complexity: $O(n) 💾 Space Complexity: $O(n) #LeetCode #JavaScript #CodingLife #Algorithms #WebDevelopment #ProblemSolving #SoftwareEngineering #TechCommunity

  • text

To view or add a comment, sign in

Explore content categories