判断一个数是否为回文数,不利用额外的空间。

思路:将数反转后进行比较。

注意:反转之后数越界的判断,若越界,则不是回文数;负数不是回文数;

代码如下:

 class Solution {
public:
bool isPalindrome(int x) {
int result = ;
int y = x;
if(x == || x < )
{
return false;
}
if(abs(x) < )
{
while(x != )
{
result = result * + x % ;
x = x / ;
}
}
else
{
int a[] = {,,,,,,,,,};
int i = ;
int flag = abs(x);
while(flag != )
{
if((flag % ) > a[i])
{
return ;
}
else if((flag % ) < a[i])
{
while(x != )
{
result = result * + x % ;
x = x / ;
}
if(result == y)
{
return true;
}
}
flag /= ;
i++;
}
}
if(result == y)
{
return true;
}
return false;
}
};

leetcode 9的更多相关文章

  1. 我为什么要写LeetCode的博客?

    # 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...

  2. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

  3. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  4. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  5. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  6. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  7. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  8. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  9. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  10. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

随机推荐

  1. js对象继承

    方法: 1.原型链继承 2.使用对象冒充继承

  2. mac eclipse 下安装subclipse

    参考 http://www.cnblogs.com/yinxiangpei/articles/3859057.html 推荐安装homebrew 在安装javahl时注意版本对应 http://sub ...

  3. 高可用集群heartbeat全攻略

    heartbeat的概念   Linux-HA的全称是High-Availability Linux,它是一个开源项目,这个开源项目的目标是:通过社区开发者的共同努力,提供一个增强linux可靠性(r ...

  4. mongodb csv 文件导入数据库,删除特定字段

    1. 导入数据库 mongoimport -h host_ip -p port -d db_name -c collection_name --fields name1,name2,name3,nam ...

  5. Thinkpad X240在Centos 7下使用ID 138a:0017或者vfs5011指纹识别

    我的笔记本是ThinknPad X240,自带的指纹识别器,通过命令lsusb可以查看: [zz@zz ~]$ lsusb Bus 001 Device 002: ID 24ae:2003 Bus 0 ...

  6. 配置FileZilla Ftp服务器

    FileZilla是我比较喜欢用的一款FTP服务端和客户端,主要使用在Windows下,她是一款开源的FTP软件,虽然在某些功能上比不上收费软件Ser-u,但她也是一款非常好用的软件,这里主要说一下这 ...

  7. 创建一个struts2的HelloWorld

    1.下载struts2的jar包 http://struts.apache.org/download.cgi#struts255 下载一个稳定版本Struts 2.3.31 里面提供了maven ja ...

  8. jquery中各个事件执行顺序如下:

    jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.e ...

  9. sql server 2008 r2 中的oracle发布使用笔记

    sql server 2008 r2 中的oracle发布功能,能够将oracle数据库作为发布服务器,将oracle中的数据自动同步到sql server 数据库中,在新建oracle发布前确保sq ...

  10. Mingyang.net:为什么不将Bean定义在Action参数中?

    Spring MVC提供了一种方便的Bean填充方式: @Controller public class CmsChannelController extends AbstractController ...