大家好,我是毛毛。ヾ(´∀ ˋ)ノ
废话不多说开始今天的解题Day~
Given an integer x
, return true if x
is palindrome integer.
An integer is a palindrome when it reads the same backward as forward. For example, 121
is palindrome while 123
is not.
Input: x = 121
Output: true
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Input: x = -101
Output: false
-2^31 <= x <= 2^31 - 1
首先先简单的翻译一下题目
给一个数字,判断是不是对称的。
作法大致上是这样
False
。class Solution:
def isPalindrome(self, x: int) -> bool:
x = str(x)
left = 0
right = len(x)-1
while left < right:
if x[left] != x[right]:
return False
left += 1
right -= 1
return True
大家明天见
>>: Day27 Javascript元件库 Jquery介绍
放烟火 1 ( 往上发射 ) 教学原文参考:放烟火 1 ( 往上发射 ) 这篇文章会介绍,如何在 S...
安全控制是风险处理的一部分,风险评估之後进行。安全控制的范围是根据风险评估的结果确定的。根据NIST...
阿嬷都看得懂的开始写第一支 .css 档案罗! 昨天我们介绍了怎麽使用 style 标签,把所有 C...
程序异常 除数为0的错误 异常处理程序try except 档案不存在的错误FileNotFoun...
撰写 Python 程序码蒐集网路上的长照相关问答资讯,相比使用人工蒐集的方式,程序自动化蒐集方便又...