From 78cc6bce7bd97924526701b90909edbf88e67221 Mon Sep 17 00:00:00 2001 From: Wen <409053122@qq.com> Date: Thu, 2 Mar 2023 11:11:17 +0800 Subject: [PATCH] =?UTF-8?q?[9]=20=E5=9B=9E=E6=96=87=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++++++++ src/leecode/python/9.回文数.py | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 src/leecode/python/9.回文数.py 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 +