Created
December 22, 2021 18:22
-
-
Save ecamellini/1c9c428cb2ee0ed83725ba992892a414 to your computer and use it in GitHub Desktop.
Solution to this problem on LeetCode: https://leetcode.com/problems/palindrome-number/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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