leetcode 9

判断一个数是否为回文数,不利用额外的空间。
思路:将数反转后进行比较。
注意:反转之后数越界的判断,若越界,则不是回文数;负数不是回文数;
代码如下:
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的更多相关文章
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [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 ...
- 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 ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
- Leetcode 笔记 101 - Symmetric Tree
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...
随机推荐
- JAVA 流式布局管理器
//流式布局管理器 import java.awt.*; import javax.swing.*; public class Jiemian2 extends JFrame{ //定义组件 JBut ...
- 一款监控网络状态的好工具- Smokeping
最近工作中需要监测某个分公司到IDC机房的网络情况,到网络上找了不少软件,发现一款叫smokeping的开源软件还不错,它是rrdtool的作者制作的,在图形显示方面很漂亮,可以用来很好的检测网络状态 ...
- 辩护技巧总结——律师在刑事辩护中应注意的几个问题 z
律师在刑事辩护中的角色就像医院中的医生对病人一样,对嫌疑人至关重要.律师的百分之一的失误,对嫌疑人来讲就是百分之百的不幸.因此我在刑事辩护中更加谨慎认真,并归纳了一些注意点供朋友参考. 一.仔细 ...
- sublime3快捷 输入html
ID and CLASS attributes html > // 直接生成整个框架 > 表示 tab建 #header <div id="header"> ...
- 下载文件的一种简单方法js
我在做的一个项目有一部分要下载附件,可是我们公司用了一个包和网上的用response的解决方法冲突,而网上的js解决方法又用到了ActiveXObj我们经理不让用这个.还好我一个同事很利害用了一个很简 ...
- git撤销命令
1 撤销工作区中master的修改 git checkout -- master.txt ,用暂存去覆盖工作区 2 git clean -n 查看哪些文件会被移除3 git clean -f 强制删除 ...
- oracle行列转换函数的使用
oracle 10g wmsys.wm_concat行列转换函数的使用: 首先让我们来看看这个神奇的函数wm_concat(列名),该函数可以把列值以","号分隔起来,并显示成一行 ...
- JQuery上传插件uploadify整理(Options)
下载 现在有两个版本了,我此次使用的依然是Flash版本的,虽然现在绝大部分浏览器都兼容HTMKL5,目前位置,除了做手机项目外,一般我们项目中不允许使用HTML5标签. 属性介绍(Options) ...
- dedecms首页怎么调用公司简介的内容
DeDeCMS功能虽然强大,但还是有些细节上的功能没有实现,正如本文描述的问题一样,DEDECMS要在网站首页调用公司简介的内容,而且还要截取前多少个字符数的时候,DEDECMS标签中没有能实现这样的 ...
- jmeter随笔(29)-关于自己的jar包和beanshell的使用
点击标题下「蓝色微信名」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是 ...