[9] 回文数

This commit is contained in:
Wen 2023-03-02 11:11:17 +08:00
parent 472c3082ef
commit 78cc6bce7b
2 changed files with 34 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,26 @@
#
# @lc app=leetcode.cn id=9 lang=python3
#
# [9] 回文数
#
# @lc code=start
# 偶数位 123321
# 12332 1233 123
# 1 12 123
# 奇数位 121
# 12 1
# 1 12
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0 or (x % 10 == 0 and x != 0):
return False
res = 0
while res < x:
res = res * 10 + x % 10
x //= 10
return res == x or res // 10 == x
# @lc code=end