7、整数反转
class Solution:
def reverse(self, x: int) -> int:
if x==0:
return 0
str_x = str(x)
x = ''
if str_x[0] == '-':
x += '-'
x += str_x[len(str_x)-1::-1].lstrip("0").rstrip("-")
x = int(x)
if -2**31<x<2**31-1:
return x
return 0
8、字符串转换整数
class Solution:
def myAtoi(self, s: str) -> int:
return max(min(int(*re.findall('^[\+\-]?\d+', s.lstrip())), 2**31 - 1), -2**31)
9、回文数
class Solution:
def isPalindrome(self, x: int) -> bool:
return True if str(x) == str(x)[::-1] else False