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aaaaaaaaaaa"
    

    and here's my javascript solution:

    var isPalindrome = function(s, start, end) {
        while (start < end) {
            if (s[start++] != s[end--]) {
                return false;
            }
        }
        return true;
    };
    
    var longestPalindrome = function(s) {
        if (s === null) return '';
        
        const length = s.length;
        var start = 0;
        var maxLength = 0;
        for (let i = 0; i < length; i++) {
            if ((i - maxLength >= 1) && (s[i] == s[i - maxLength - 1])) {
                start = i - maxLength - 1;
                maxLength += 2;
            }
            if ((i - maxLength >= 0) && isPalindrome(s, i - maxLength, i)) {
                start = i - maxLength;
                maxLength++;
            }
        }
        return s.substring(start, start + maxLength);
    };
    

    What's wrong with this code?


  • 0
    C

    @Arthur-Conan-Dog
    I was getting Runtime Errors at same "aaaaaaaaaaaa..." test case trying to submit my C# solution couple nights ago, I think it was a temp LC engine glitch because I submitted same code today and it got accepted.

    For your JavaScript code above, I submitted it just now and got a failure at this testcase:

    0_1498788526387_6e8a54ee-94c4-4c75-baa3-25c58a2bcb5c-image.png


  • 0
    C
    This post is deleted!

  • 0
    A

    @c8b2b9ef I used a simple but wrong method in 1st if statement to detect palindrome substrings, fixed it already. Thanks bro:)


Log in to reply
 

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