Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

Some hints:

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?

There is a more generic way of solving this problem.

判断一个整形数字是否为回文串

 public class Solution {
public boolean isPalindrome(int x) {
int res =0;
int temp = 0;
int begin = x;
if(x<0) return false;
while(x!=0){
temp = temp * 10 + x % 10;
if(temp>Integer.MAX_VALUE) return false;
res = temp;
x /=10;
}
if(begin == res )
return true;
else
return false;
}
}

总结:这个题和reverse ingeter 非常类似,区别在于他没有负数,同时如果你的反过来超过了最大值那么肯定不是回文数,如果没超过的话再去对比和原数是否相等,相等的话才是回文

最新文章

  1. stm32 usb error : identifier &quot;bool&quot; is undefined
  2. Greedy --- HNU 13320 Please, go first
  3. java获取页面编码
  4. iOS中nil、Nil、NULL、NSNull详解(转)
  5. android学习笔记34——ClipDrawable资源
  6. cocos2d-x Action
  7. hdu 4507 数位dp(求和,求平方和)
  8. TCP/IP(七)之玩转HTTP协议
  9. 模仿bootstrap做的 js tooltip (添加鼠标跟随功能)
  10. 未能找到类型或命名空间名称“Quartz”
  11. FineUI经典项目展示(2)基础管理系统(附在线演示)
  12. Newtonsoft.Json添加项
  13. Postgresql_根据执行计划优化SQL
  14. Util.FSUtils: Waiting for dfs to exit safe mode
  15. Eclipse的配置
  16. MySQL 之mydumper安装详解
  17. datagrid 扩展 页脚 合计功能
  18. H5——video百花齐放(浏览器自带的播放器)
  19. IP设置-内置服务器-外置服务器
  20. Bzoj1496: [NOI2006]千年虫

热门文章

  1. Mongodb基础用法及查询操作[转载]
  2. 实现自己的.NET Core配置Provider之Yaml
  3. 转载: C++ 获取文件夹下的所有文件名
  4. Ionic/Angularjs 知识点解析
  5. 解决SQL Server 阻止了对组件 &#39;Ad Hoc Distributed Queries&#39; 的 STATEMENT &#39;OpenRowset/OpenDatasource&#39; 的访问
  6. Python库:序列化和反序列化模块pickle介绍
  7. PHP面向对象概述
  8. Laravel安装及环境的配置(XAMPP集成开发环境下)
  9. USB的前世今生
  10. 线程高级.md