class Solution:
def isPalindrome(self, x: int) -> bool:
# If x is a negative number it is not a palindrome
# If x % 10 = 0, in order for it to be a palindrome the first digit should also be 0
if x < 0 and x%10 == 0):
return False
reversedNum = 0
while x > reversedNum:
reversedNum = reversedNum * 10 + x % 10
x = x // 10
# If x is equal to reversed number then it is a palindrome
# If x has odd number of digits, dicard the middle digit before comparing with x
# Example, if x = 23132, at the end of for loop x = 23 and reversedNum = 231
# So, reversedNum/10 = 23, which is equal to x
return True if (x == reversedNum or x == reversedNum // 10) else False
< /code>
Это мой код, который дает неправильный вывод для 660,
ожидаемый выход: false
my output: true < /p>
может кто -нибудь сказать мне, как исправить это. < /p>
Подробнее здесь: https://stackoverflow.com/questions/738 ... -in-python
Номер палиндрома в Python ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение