Need help!! My C++ code has problem of Time Limit Exceeded.


  • 0
    V
    class Solution {
    public:
        bool isPalindrome(string s) 
        {
            if("" == s)
                return true;
            string temp1 = "";
            string temp2 = "";
            for(int i = 0; i < s.size(); i++)
            {
                if(s[i] >= 'a' && s[i] <= 'z')
                {
                    temp1 = temp1 + s[i];
                    temp2 = s[i] + temp2;
                }
                if(s[i] >= 'A' && s[i] <= 'Z')
                {
                    char p = s[i] + 'a' - 'A';
                    temp1 = temp1 + p;
                    temp2 = p + temp2;                
                }
            }
            if(temp1 == temp2)
                return true;
            else
                return false;        
        }
    };

Log in to reply
 

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