9. Palindrome Number回文数(Easy,LeetCode)

9. Palindrome Number [easy] (Python) 题目链接https://leetcode.com/problems/palindrome-number/题目原文 Determine whether an integer is a palindrome. Do this without extra space. 题目翻译判断一个整数(integer)是否是回文,不要使用额外的空间。思路方法该题目还有一些官方的提示: Some hints: 阅读详情

Given an integer x, return true if x is palindrome integer.

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

An integer is a palindrome when it reads the same backward as forward.

  • For example, 121 is a palindrome while 123 is not.

回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121 是回文,而 123 不是。

Example 1:

Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.

Example 2:

Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
解释:从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。

Example 3:

Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
解释:从右向左读, 为 01 。因此它不是一个回文数。

Constraints:提示:

  • -2^{31} <= x <= 2^{31} - 1

Follow up: Could you solve it without converting the integer to a string?

进阶:你能不将整数转为字符串来解决这个问题吗?

C语言:

bool isPalindrome(int x){
    long n=x,r=0;
    if(x<0) return false;
    if(x==0)    return true;
    while(n>0)
    {
        r=r*10+n%10;
        n=n/10;
    }
    return r==x;
}

执行结果:通过

执行用时:12 ms, 在所有 C 提交中击败了43.77%的用户

内存消耗:5.7 MB, 在所有 C 提交中击败了75.78%的用户

通过测试用例:11510 / 11510

不明白为什么int运行失败,只能把int改为long。

C语言:

bool isPalindrome(int x){
    long n=x,r=0;
    if(x<0) return false;
    if(x==0)    return true;
    while(n>0)
    {
        r=r*10+n%10;
        n=n/10;
    }
    if(r==x)
        return true;
    else
        return false;
}

执行结果:通过

执行用时:16 ms, 在所有 C 提交中击败了20.22%的用户

内存消耗:5.8 MB, 在所有 C 提交中击败了41.38%的用户

通过测试用例:11510 / 11510

C语言:

bool isPalindrome(int x){
    int i=0,j=0;
    char s[11]={'\0'};
    if(x<0) return false;
    if(x==0)    return true;
    while(x>0)
    {
        s[i]=x%10+'0';
        x=x/10;
        i++;
    }
    i--;
    while(j<i)
    {
        if(s[i]!=s[j])  return false;
        i--;
        j++;
    }
    return true;
}

执行结果:通过

执行用时:8 ms, 在所有 C 提交中击败了73.44%的用户

内存消耗:5.7 MB, 在所有 C 提交中击败了71.46%的用户

通过测试用例:11510 / 11510

LeetCode9 Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Java AC版本 立即下载

相关推荐

四旋翼无人机数学模型推导

本周开始进行四旋翼无人机的学习工作,首先来进行四旋翼无人机的数学模型推导工作。。 四旋翼动力学数学模型 坐标变换 介绍四旋翼数学模型之前,首先引入坐标变换的概念,定义两个坐标系惯性坐标系{E},以及机体坐标系{B},惯性坐标系就相当于在地面建立的、静止不动的坐标系,也是我们操纵无人机所在的空间,而机体坐标系是建立于四旋翼机体之上,随着四旋翼姿态变换而变化,所以建立一种地面上的惯性坐标系与四旋翼机体坐标系之间的转换关系,就有这个必要。 对于惯性坐标系{E},以及机体坐标系{B},它们之间的转换关系

BiuBiuSun的博客 1万+

9. Palindrome Number(回文数)

Determine whether an integer is a palindrome. An integerisapalindrome when itreads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -12...

aodubi0638的博客 259

企业华为TaurusDB数据库国产替代要点全记录

国产化数据库全方位对比、从互联网企业的先进经验来看mysql的用法、及sql优化、sql异构修改、及数据同步方面都做了一些讲解

深耕互联网的码农,在AI及国产化浪潮下,希望把自己的能力输出给更多的人 1069

9. Palindrome Number

Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not. Example 1: Input: x = 121 Output: true Example 2: Input: x = -121 Output

云淡风轻_的博客 224

error C2039: “int_least8_t”: 不是“`global namespace'”的成员

在向H.265的测试软件HM16.0中配置boost的时候,发现 include &lt;boost/cstdint.hpp&gt;的时候总是会报错:错误 11 error C2039: “int_fast16_t”: 不是“`global namespace'”的成员 D:\Program Files\Caffe\VSContact\boost_1_58_0\boost\cstdint.hpp ...

flyerene的博客 1万+

CAN总线错误帧全解析:从数据包到硬件层的故障树分析

本文深入解析CAN总线错误帧的故障树分析方法,从数据包到硬件层全面剖析错误机制。通过物理层信号测试、数据链路层错误解码和应用层协议排查,提供系统化的诊断框架。结合CANoe配置和示波器波形分析,帮助工程师快速定位总线故障,提升系统可靠性。

weixin_26742753的博客 507

9. Palindrome Number【回文数字】

描述 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数 例子 思路 方法1: 把数字变为字符串,然后比较–效率最低 ...

puspos的博客 514

通达信指标-A214【十全十美 十剑共振】

【代码】通达信指标-A214【十全十美 十剑共振】

2012年开始工作,全栈开发老兵,目前已是一个老师,分享这么多年的心得体会 143

【LeetCode】 9. Palindrome Number 回文数(Easy)(JAVA)

【LeetCode】 9. Palindrome Number 回文数(Easy)(JAVA) 题目地址: https://leetcode.com/problems/palindrome-number/ 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the...

qq_16927853的博客 201

Coze 上 OpenClaw 完整使用攻略(零代码 + 24 小时在线 + 飞书 / 微信接入)

Coze(扣子)是目前国内零门槛部署 OpenClaw 最友好的平台,无需服务器、不用命令行,5 分钟即可拥有可执行本地 / 云端任务的 AI 助手,还能一键发布到飞书、微信、钉钉等 IM。

hy行者勇哥的博客 2940

Vue 前端导出页面A4大小pdf,Vue前端导出pdf自动切割换页不切割内容 Vue导出页面pdf自动分页和添加页码 导出的pdf提高清晰度

【代码】Vue 前端导出页面A4大小pdf,Vue前端导出pdf自动切割换页不切割内容 Vue导出页面pdf自动分页和添加页码 导出的pdf提高清晰度。

weixin_41346436的博客 1803

LeetCode题解-python 9.回文数 Palindrome Number (Easy)

9.回文数 Palindrome Number (Easy) 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。 示例 3: 输入: 10 输出: false 解释: 从右...

LKY111的专栏 360

2015年高教社杯全国大学生数学建模竞赛 A 题:《太阳影子定位》真题解析与 MATLAB 解决方案

🏆 本文已收录于专栏:《滚雪球学数学建模(含历年真题)》,持续更新最新及历年数学建模竞赛资料,每篇内容力求做到“问题讲透、模型讲清、代码可用、论文可参考”,帮助你从零开始逐步建立完整的数学建模知识体系。

**My Coding Family** 1369

LeetCode 9.Palindrome Number(回文数) 数学/easy

文章目录1.Description2.Example3.Solution 1.Description 给你一个整数 x ,如果 x 是一个回文整数,返回 ture ;否则,返回 false 。 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121 是回文,而 123 不是。 2.Example 示例 1: 输入:x = 121 输出:true 示例 2: 输入:x = -121 输出:false 解释:从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回

押切徹的博客 277

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

LeetCode刷题记录

LeetCode刷题记录 EASY 正式开始LeetCode刷题之旅,万事开头难,然后中间难,最后结尾难… 1. Two Sum Easy Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each...

suanbian3234的博客 172

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

LeetCode 9. Palindrome Number (Java版; Easy)

welcome to my blog LeetCode Top Interview Questions 9. Palindrome Number (Java版; Easy) 题目描述 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t...

littlehaes的博客 338

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

LeetCode 9 Palindrome Number (easy)——python

题目来源:                       https://leetcode.com/problems/palindrome-number/description/  题目分析:       本题要我们判断一个整数是否是回文数,Do this without extra space.这句,当时我的理解是说在输入时不要留有空格,因此我写的程序较为简单,没有判断溢出等情况,有大神

revivre的博客 284

[LeetCode] 009. Palindrome Number (Easy) (C++/Java/Python)

[LeetCode] 009. Palindrome Number (Easy) (C++/Java/Python)

水果君の日常 3276

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

题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: f...

weixin_30689307的博客 133

[Leetcode 9, Easy] Palindrome Number

Leetcode, Easy

算法的实践 438

Leetcode 9. Palindrome Number [easy] [java]

Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example Solution 1 class Solution { public boolean isPalin...

inkhk的博客 236

【python3】leetcode 9. Palindrome Number(easy)

 9. Palindrome Number(easy) Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: ...

momottyy的专栏 191

LeetCode OJ 9 Palindrome Number [easy]

题目描述: Determine whether aninteger is a palindrome. Do this without extra space. Some hints: Could negativeintegers be palindromes? (ie, -1) If you are thinkingof converting the integer to string,

大吱的博客 373

【Leetcode】9. 判断回文数(Palindrome Number)

Leetcode - 9 Palindrome Number (Easy) Input: -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. public boolean i...

厉兵秣码 260

leetcode 9 Palindrome Number

Palindrome Number Total Accepted: 74363 Total Submissions: 261192 Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Co

javays1的专栏 382
上一篇: Go语言的包
下一篇: Go语言的并发编程
DXB2021
博客等级 码龄5年 307粉丝 289原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值