sudheerj / datastructures-algorithms

List of Programs related to data structures and algorithms
448 stars 124 forks source link

[bug] In longestPalindromicSubstring, right is not incremented or decremented #9

Closed jdegand closed 3 months ago

jdegand commented 4 months ago

In the even length section, right is not incremented or decremented.

        left = i; right = i+1;
        while(left >=0 && right < str.length && str[left] === str[right]) {
            if(right-left+1 > longestSubstrLen) {
                longestSubstr = str.substring(left, right+1);
                longestSubstrLen = right-left+1;
            }
            left--;
            right;  
sudheerj commented 3 months ago

@jdegand Thanks for the finding. I will fix it .

sudheerj commented 3 months ago

@jdegand Fixed.