Leetcode 125 Solution

This article provides solution to leetcode question 125 (valid-palindrome)

https://leetcode.com/problems/valid-palindrome

Solution

class Solution { public: bool isPalindrome(string s) { string v;
for (auto it = s.begin(); it != s.end(); it++) { if ('A' <= *it && *it <= 'Z') { v += *it - ('A' - 'a'); } else if (('a' <= *it && *it <= 'z') || ('0' <= *it && *it <= '9')) { v += *it; } }
int l = 0; int r = v.size() - 1;
while (l <= r) { if (v[l++] != v[r--]) return false; }
return true; } };