9.leetcode 回文数(简单)

leetcode python 刷题记录,从易到难


一、题目

在这里插入图片描述


二、解答

1.思路

转换成字符串,判断反转后的和未反转的是否相等,相等返回True,否则返回False。

2.实现

class Solution(object):
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        result = str(x)
        if result[::-1] == str(x):
            return True
        else:
            return False

3.提交结果

在这里插入图片描述

三、Github地址

https://github.com/m769963249/leetcode_python_solution/blob/master/easy/9.py


相似题目:

  1. 整数反转

参考链接

https://leetcode-cn.com/

猜你喜欢

转载自blog.csdn.net/qq_39945938/article/details/107294568