please see comments, two different while loop conditions have different outcomes, is this because of and
operator? I couldn't figure out why.
def longestPalindrome(s: str) -> str:
output = ""
for i in range(len(s)):
temp = check(s,i,i)
if len(output) < len(temp):
output = temp
temp = check(s,i,i+1)
if len(output) < len(temp):
output = temp
return output
def check(s: str, l: int, r: int) -> str:
while (l >= 0 and r < len(s) and s[l] == s[r]):
# while (s[l] == s[r] and l >= 0 and r < len(s)):
# above will result in 'string index out of range' error which I couldnt figure out why
l-=1;r+=1
return s[l+1:r]
print(longestPalindrome("adaa")) # this will return "ada"