Time Limit Exceeded Problem


  • 0
    J

    "Time Limit Exceeded" happens when I meet the test case below with my code. But eclipse tell me right.

    "A man a plan a cameo Zena Bird Mocha Prowel a rave Uganda Wait a lobola Argo Goto Koser Ihab Udall a revocation Ebarta Muscat eyes Rehm a cession Udella ... (more than 327676 characters.)
    a canal Panama!"

    My code is shown :
    """
    public boolean isPalindrome(String s) {
    if (s.isEmpty()) return true;
    String str = "";
    for(int i =0; i < s.length(); i++) {
    char ch = s.charAt(i);
    if (Character.isLetter(ch) || Character.isDigit(ch)) {
    ch = Character.toLowerCase(ch);
    str = str + ch;
    }
    }
    int len = str.length();
    for (int i=0;i<len/2;i++) {
    char ch = str.charAt(i);
    char ch1 = str.charAt(len-1-i);
    if (ch!=ch1) return false;
    }
    return true;
    }
    """


Log in to reply
 

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