diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -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 diff --git a/src/leecode/python/9.回文数.py b/src/leecode/python/9.回文数.py new file mode 100644 index 0000000..6e500ae --- /dev/null +++ b/src/leecode/python/9.回文数.py @@ -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 +