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
相关推荐
superman超哥4 小时前
仓颉语言中基本数据类型的深度剖析与工程实践
c语言·开发语言·python·算法·仓颉
Learner__Q5 小时前
每天五分钟:滑动窗口-LeetCode高频题解析_day3
python·算法·leetcode
阿昭L5 小时前
leetcode链表相交
算法·leetcode·链表
闻缺陷则喜何志丹5 小时前
【计算几何】仿射变换与齐次矩阵
c++·数学·算法·矩阵·计算几何
liuyao_xianhui5 小时前
0~n-1中缺失的数字_优选算法(二分查找)
算法
hmbbcsm6 小时前
python做题小记(八)
开发语言·c++·算法
机器学习之心6 小时前
基于Stacking集成学习算法的数据回归预测(4种基学习器PLS、SVM、BP、RF,元学习器LSBoost)MATLAB代码
算法·回归·集成学习·stacking集成学习
图像生成小菜鸟6 小时前
Score Based diffusion model 数学推导
算法·机器学习·概率论
声声codeGrandMaster7 小时前
AI之模型提升
人工智能·pytorch·python·算法·ai
黄金小码农7 小时前
工具坐标系
算法