← Back to LeetCode Notes

125. Valid Palindrome

easy · two-pointers · string · solved 2026.07.16 · 10 sec read

View on LeetCode ↗
C++
class Solution {public:    bool isPalindrome(string s) {        std::transform(s.begin(), s.end(), s.begin(), ::toupper);        int begininning = 0;        int end = s.size() - 1;        while (end >= begininning) {            if (!isalnum(s[begininning])) {                begininning++;                continue;            }            if (!isalnum(s[end])) {                end--;                continue;            }            if (s[begininning] != s[end]) return false;            end--;            begininning++;        }        return true;    }};

simple two pointer i did as warm up, just got tripped up on string functions.