直接上python代码

class Solution:
def isPalindrome(self, x: int) -> bool:
if x<0: //负数必不是回文数
return 1==0
sws = []
for i in str(x): //将x反转然后判断是否相等
sws.append(i)
sws.reverse()
sws = ''.join(sws)
return x == int(sws)
class Solution:
def isPalindrome(self, x: int) -> bool:
s = list(str(x))
t = s[::-1] //暴力取反
return t==s

C语言

bool isPalindrome(int x){
if (x < 0 || (x % 10 == 0 && x != 0)) //小于0,最后一位数为0都不是回文数
return false;
int n=0,x_0=x,i=0;
while(x)
{
if(i == 9 && (x_0%10)>2) //溢出的也不是回文数
return false;
n = n*10 + x%10; //对x取反
x = x/10;
i += 1;
}
return n == x_0;
}

题目来源:9. 回文数 - 力扣(LeetCode) (leetcode-cn.com)

Leetcode回文数的更多相关文章

  1. leetcode 回文数

    判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...

  2. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  3. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

  4. LeetCode 5回文数

    判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...

  5. leetcode isPalindrome (回文数判断)

    回文很简单,就是正着读和反着读一样,要判断一个数是否为回文数只需要判断正反两个是不是相等即可. 再往深了想一下,只需要判断从中间分开的两个数一个正读,一个反读相等即可. 代码: class Solut ...

  6. 【LeetCode】Palindrome Number(回文数)

    这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...

  7. 【LeetCode】9、Palindrome Number(回文数)

    题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...

  8. Leetcode(9)回文数

    Leetcode(9)回文数 [题目表述]: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 第一次:直接全部转 执行用时:148 ms: 内存消耗:13.4 ...

  9. [LeetCode] 906. Super Palindromes 超级回文数

    Let's say a positive integer is a superpalindrome if it is a palindrome, and it is also the square o ...

  10. 【LeetCode】 #9:回文数 C语言

    目录 题目 思路 初步想法 进一步想法 最后想法 总结 最近打算练习写代码的能力,所以从简单题开始做. 大部分还是用C语言来解决. @(解法) 题目 判断一个整数是否是回文数.回文数是指正序(从左向右 ...

随机推荐

  1. opencv-python中 boundingRect(cnt)以及cv2.rectangle用法

    矩形边框(Bounding Rectangle)是说,用一个最小的矩形,把找到的形状包起来.还有一个带旋转的矩形,面积会更小,效果见下图 首先介绍下cv2.boundingRect(img)这个函数 ...

  2. openpyxl 设置某列单元格样式

    1 # 边框线 2 border_set = Border(left=Side(border_style='thin', color='000000'), 3 right=Side(border_st ...

  3. Nginx快速入门:简介、安装、配置

    Nginx概述 与 Apache 软件类似,Nginx ("engine x")是一个开源的.支持高性能.高并发的web服务和代理服务软件.它是由俄罗斯人 Igor Sysoev ...

  4. zookeeper运维常用指令

    zkServer.sh ./zkServer.sh start:启动zookeeper ./zkServer.sh stop:停止zookeeper ./zkServer.sh status:查看zo ...

  5. 【pytorch】目标检测:YOLO的基本原理与YOLO系列的网络结构

    利用深度学习进行目标检测的算法可分为两类:two-stage和one-stage.two-stage类的算法,是基于Region Proposal的,它包括R-CNN,Fast R-CNN, Fast ...

  6. 论文解读(MetaAdapt)《MetaAdapt: Domain Adaptive Few-Shot Misinformation Detection via Meta Learning》

    Note:[ wechat:Y466551 | 可加勿骚扰,付费咨询 ] 论文信息 论文标题:MetaAdapt: Domain Adaptive Few-Shot Misinformation De ...

  7. ATtiny88初体验(四):看门狗

    ATtiny88初体验(四):看门狗 ATtiny88单片机的看门狗使用内部独立的128KHz时钟源,拥有3种工作模式: Interrupt模式:超时产生中断: System Reset模式:超时产生 ...

  8. 使用 Sealos 在离线环境中光速安装 K8s 集群

    作者:尹珉.Sealos 开源社区 Ambassador,云原生爱好者. 当容器化交付遇上离线环境 在当今快节奏的软件交付环境中,容器化交付已经成为许多企业选择的首选技术手段.在可以访问公网的环境下, ...

  9. Paddle图神经网络训练-PGLBox代码阅读笔记

    图存储部分 paddle/fluid/framework/fleet/heter_ps graph_gpu_wrapper.h GPU图主入口 graph_gpu_ps_table.h GPU图的主要 ...

  10. [WPF]使用HLSL实现百叶窗动效

    百叶窗动画是制作PPT时常用的动画之一,本文将通过实现百叶窗动画效果的例子介绍在WPF中如何使用ShaderEffect.ShaderEffect是使用高级着色器语言(High Level Shadi ...