1
class Solution:
def longestPalindrome(self, s: str) -> str:        
    
    def is_palin(window: int, start: int) -> str:            
        while window <= len(s) and start <= len(s) - window:
            print(f'window size : {window} start {start} string {s[start: start + window]} {s[start: start + window][::-1]}')
            
            if s[start: start + window] == s[start: start + window][::-1]:
                    ans = s[start: start + window]
                    print(ans)
                    return ans
            
            start += 1
            print("loop end")
            
        window -= 1
        if window == 0:
            return
        
        is_palin(window, 0)
                   
    
    return is_palin(len(s), 0)
    

I am expecting that "print(ans)" which in result prints "bab" to be returned as ans, then returned as is_palin(len(s), 0).

but it returns "None".....

this is stdout window size : 5 start 0 string babad dabab

loop end

window size : 4 start 0 string baba abab

loop end

window size : 4 start 1 string abad daba

loop end

window size : 3 start 0 string bab bab

bab

what is the problem? pls help.

Sprout
  • 11
  • 3

0 Answers0