Skip to content

Instantly share code, notes, and snippets.

@ecamellini
Created December 22, 2021 18:22
Show Gist options
  • Save ecamellini/1c9c428cb2ee0ed83725ba992892a414 to your computer and use it in GitHub Desktop.
Save ecamellini/1c9c428cb2ee0ed83725ba992892a414 to your computer and use it in GitHub Desktop.
Solution to this problem on LeetCode: https://leetcode.com/problems/palindrome-number/
class Solution:
def isPalindrome(self, x: int) -> bool:
xStr = str(x)
for i in range(0, len(xStr)):
if xStr[i] != xStr[-(i+1)]:
return False
# Qua il ciclo è finito!
return True
if __name__ == "__main__":
sol = Solution()
assert sol.isPalindrome(121) is True
assert sol.isPalindrome(1221) is True
assert sol.isPalindrome(1222) is False
assert sol.isPalindrome(213123213213) is False
assert sol.isPalindrome(123456890098654321) is True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment