力扣第九题

回文数

提示:

给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。

回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。

代码展示:

class Solution:
    def isPalindrome(self, x: int) -> bool:
        # 负数不是回文数
        if x < 0:
            return False

        # 将整数转换为字符串
        str_x = str(x)

        # 检查字符串是否是回文
        return str_x == str_x[::-1]


# 示例使用
sol = Solution()
print(sol.isPalindrome(121))  # 输出 True
print(sol.isPalindrome(-121))  # 输出 False
print(sol.isPalindrome(10))  # 输出 False

截屏展示:

相关推荐

  1. 经典150:跳跃游戏

    2024-07-15 11:22:04       33 阅读
  2. 经典150三十:赎金信

    2024-07-15 11:22:04       32 阅读
  3. 202“快乐数”

    2024-07-15 11:22:04       27 阅读
  4. 204“计数质数”

    2024-07-15 11:22:04       26 阅读
  5. 228“汇总区间”

    2024-07-15 11:22:04       23 阅读
  6. 经典150:多数元素

    2024-07-15 11:22:04       34 阅读
  7. 】每日一70,爬楼梯

    2024-07-15 11:22:04       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 11:22:04       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 11:22:04       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 11:22:04       62 阅读
  4. Python语言-面向对象

    2024-07-15 11:22:04       72 阅读

热门阅读

  1. 云原生存储解决方案

    2024-07-15 11:22:04       20 阅读
  2. 【LeetCode】最小栈

    2024-07-15 11:22:04       23 阅读
  3. Ionic 加载动画

    2024-07-15 11:22:04       20 阅读
  4. Yolo,输出的参数的含义

    2024-07-15 11:22:04       31 阅读
  5. 切换node版本

    2024-07-15 11:22:04       22 阅读
  6. 墨烯的C语言技术栈-C语言基础-014

    2024-07-15 11:22:04       23 阅读
  7. 从零手写实现 nginx-28-error pages 指令

    2024-07-15 11:22:04       26 阅读
  8. 什么是JVM进程

    2024-07-15 11:22:04       28 阅读
  9. PHP7.4编译安装

    2024-07-15 11:22:04       21 阅读
  10. GBNF Guide

    2024-07-15 11:22:04       24 阅读