leetcode 9. 回文数

  1. 偷懒的方式
python 复制代码
class Solution:
    def isPalindrome(self, x: int) -> bool:
        s = str(x)
        return s == s[::-1]
  1. 正经的方式
python 复制代码
class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x < 0 or (x % 10 == 0 and x != 0):
            return False
        rev = 0
        temp = x
        while(temp):
            rev = rev * 10 + temp%10
            temp = temp//10

        return rev==x
相关推荐
爪哇部落算法小助手5 分钟前
每日两题day65
数据结构·c++·算法
麒qiqi14 分钟前
【数据结构核心篇】树与哈希(Hash)的原理、特性及实战应用
数据结构·算法·哈希算法
Swift社区15 分钟前
LeetCode 443. 压缩字符串
leetcode·职场和发展·蓝桥杯
ada7_17 分钟前
LeetCode(python)——543.二叉树的直径
数据结构·python·算法·leetcode·职场和发展
橘颂TA17 分钟前
【剑斩OFFER】算法的暴力美学——颜色分类
数据结构·c++·算法·动态规划
吴秋霖23 分钟前
profileData纯算逆向分析
算法·设备指纹·反爬虫技术
sprintzer24 分钟前
11.26-12.05力扣栈刷题
算法·leetcode·职场和发展
sin_hielo36 分钟前
leetcode 3578
数据结构·算法·leetcode
ShiMetaPi1 小时前
SAM(通用图像分割基础模型)丨基于BM1684X模型部署指南
人工智能·算法·ai·开源·bm1684x·算力盒子
前端小白在前进1 小时前
力扣刷题:无重复字符的最长子串
算法·leetcode·职场和发展