【LeetCode】9 Palindrome Number 回文数判定
题目:
Determine whether an integer is a palindrome. Do this without extra space.
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
思路:这题比较简单,可以把数字翻转与原数进行比对。需要注意的是负数的判定以及翻转之后可能会产生溢出的问题。
public class Solution {
public boolean isPalindrome(int x) {
if(x<0) return false;
long res=0;
long lx=x;
while(lx!=0){
res=res*10+lx%10;
lx/=10;
}
return res==x;
}
}
---恢复内容结束---
【LeetCode】9 Palindrome Number 回文数判定的更多相关文章
- leetcode 9 Palindrome Number 回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- Leetcode 3——Palindrome Number(回文数)
Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...
- [LeetCode]9. Palindrome Number回文数
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
- 【LeetCode】Palindrome Number(回文数)
这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...
- LeetCode Problem 9:Palindrome Number回文数
描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
- 【LeetCode】9. Palindrome Number 回文数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...
- [LeetCode] Prime Palindrome 质数回文数
Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...
- Palindrome Number 回文数
判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出. ...
- 9. Palindrome Number 回文数的判断
[抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ...
随机推荐
- Linux命令总结_查看主机磁盘使用
1.dh -h 查看各个挂载点的使用量 2.du -sh *(星号表示当前所有文件夹)可以查看当前目录下各个文件夹的大小,-s表示只显示当前文件夹(不加-s你可以看到所有文件夹下的子文件夹的大小,太多 ...
- SpringBoot使用拦截器无效
附上代码: public class WendaWebConfiguration extends WebMvcConfigurerAdapter { @Autowired PassportInterc ...
- CI框架3.0版本以后,前后台分离的方法。
笔者认为,CI框架官方其实并没有考虑这个前后台分离的问题,所以没有官方的分离方法.而且,2.0版本的分离,也被官方认为这是一个bug.所以在前后台分离这个问题上,其实并不如thinkphp框架. 在C ...
- ASP.NET自定义控件组件开发
ASP.NET的开发都是事件驱动的,现在我们就来为控件添加事件.在事件之前 对委托事件要要熟悉. 其实定义事件的步骤很简单: 1.声明一个委托. 2.定义一个携带事件信息的类. 3.定义事件 4.定义 ...
- 外网连接Mysql云数据库
购买好Mysql云数据库,这里是腾讯云 在管理中把外网地址开通,然后可以看到本云数据库的外网地址 注意:外网地址com到前面才是连接地址,冒号后面的10057是连接的端口号,可以看下面的连接语句 cm ...
- react-native-contact 安卓已测试,
1. 下载模块 npm install react-native-contacts --save 2.安卓配置: a.在android/settings.gradle include ':rea ...
- MySQL事务学习
- vue教程4-vueadmin上手
项目地址 https://github.com/PanJiaChen/vue-admin-template 这是一个 极简的 vue admin 管理后台 它只包含了 Element UI & ...
- MyIfmHttpClient
package com.yd.ifm.client.caller.util.http; import java.util.Map; import com.yd.ifm.client.caller.mo ...
- 规则引擎.Net Core
.Net Core 环境下构建强大且易用的规则引擎 https://www.cnblogs.com/chenug/p/9160397.html 本文源码: https://github.com/jon ...