9. palindrome number (python 3)

why this takes 36 ms

class Solution:
    def isPalindrome(self, x: int) -> bool:
        s = str(x)
        if (s == s[::-1]):
            return True
        else:
            return False

and this takes 64 ms even though they are quite similar and both on python 3

class Solution:
    def isPalindrome(self, x: int) -> bool:
        
        s = str(x)
        return (s == s[ :: -1])
Comments (1)