Share my 12ms c++ solution


  • 2
    R
    class Solution {
    public:
        bool isPalindrome(string s) {
            int start = 0, end = s.length() - 1;
            while (start < end) {
                char cs = tolower(s[start]), ce = tolower(s[end]);
                if (!isalnum(cs)) {
                    ++start;
                    continue;
                }
                if (!isalnum(ce)) {
                    --end;
                    continue;
                }
                if (cs != ce) return false;
                ++start;
                --end;
            }
            return true;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.