clueless coding // TODO: be smarter

LeetCode Valid Palindrome: CPP Solution



TL;DR Code Solution


bool isPalindrome(string s) {

    int left = 0;
    int right = s.length() - 1;

    while (left < right) {
        if (!isalnum(s[left])) {
            left++;
        }
        else if (!isalnum(s[right])) {
            right--;
        }
        else {

            if (tolower(s[left]) != tolower(s[right])) {
                return false;
            }
            left++;
            right--;

        }


    }

    return true;

}