+ 1

(A time limit)Given the string, check if it is a palindrome.

[execution time limit] 4 seconds (py3) Here’s my code, I want to know how to make it faster,thank you very much ᕕ(ᐛ)ᕗ def checkPalindrome(inputString): inputString = input("Please output a string: ") if len(inputString) < 10**5 and len(inputString) > 1 : return (inputString == inputString[::-1])

14th Apr 2018, 6:19 AM
ChaoShi
ChaoShi - avatar
3 Antworten
0
def checkPalindrome(inputString): reverseString=((inputString)[::-1]) if inputString==reverseString: return True else: return False
14th Apr 2018, 6:40 AM
ChaoShi
ChaoShi - avatar
0
that's faster😅
14th Apr 2018, 6:41 AM
ChaoShi
ChaoShi - avatar
0
str = input() print (True if str == str[::-1] else False) and you can just turn it in to a function by doing def pal(str) print (True if str == str[::-1] else False)
14th Apr 2018, 6:52 AM
Obbu
Obbu - avatar