def is_palindrome2(s): left = 0 right = len(s) - 1 while left < right: if s[left]!= s[right]: return False left += 1 right -= 1 return True string = "racecar" if is_palindrome2(string): print(f"{string} 是回文串") else: print(f"{string} 不是回文串")

相关推荐

牛客网
牛客企业服务