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.
Example 1:
Input: x = 121
Output: true
Example 2:
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.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Example 4:
Input: x = -101
Output: false
Constraints:
-231 <= x <= 231 - 1
class Solution:
def isPalindrome(self, x: int) -> bool:
num = str(x)
reverse = num[::-1]
if num==reverse:
return True
else:
return False
以下是在讨论区看到别人的做法
def isPalindrome(self, x: int) -> bool:
if x<0:
return False
inputNum = x
newNum = 0
while x>0:
newNum = newNum * 10 + x%10
x = x//10
return newNum == inputNum
今天偷懒只写了一题easy的
而且还使用了小作弊的方法
明天要进去实验室了
今天在进行收心操的部分
祝我顺利
也希望大家连假後的明天都顺利!!
今天我们要开始体验 Ramda,请大家到 Ramda.js 官网安装 Ramda 後, 就可以开始以...
所谓测试驱动开发(Test-driven development, TDD),即「先写测试再开发」,...
今年是台股放量的一年,也是新一代韭菜毕业的一年 很多人提到无本当冲多好赚之类的 但当冲没看懂方向真的...
这篇主要是根据网路上的 Code 建立的(其实是看书学的),主要是用来了解 UITableView...
可曾想过一家企业有着IT与非IT背景的团队(例如:行销部门)共事, 企业如何运用这些人才解决这每日堆...