class Solution {
public:
bool isPalindrome2(int x) {//二进制
int num=1,len=1,t=x>>1;
while(t){
num<<=1;
t>>=1;
len++;
}
len/=2;
while(len--){
if((num&x==0)&&(x&1)!=0){
return 0;
}
x&=(~num);
x>>=1;
num>>=2;
}
return 1;
}
bool isPalindrome(int x) {//十进制
if(x<0)return 0;
int num=1,len=1;
while(x/num>=10){
num*=10;
len++;
}
len/=2;
while(len--){
if(x%10!=x/num){
return 0;
}
x=x-(x/num)*num;
num/=100;
x/=10;
}
return 1;
}
};

[LeetCode]Palindrome Number 推断二进制和十进制是否为回文的更多相关文章

  1. 9. Palindrome Number(判断整型数字是否是回文,直接暴力即可)

    Determine whether an integer is a palindrome. Do this without extra space. class Solution: def isPal ...

  2. [LeetCode]Palindrome Partitioning 找出所有可能的组合回文

    给定一个字符串,切割字符串,这样每个子字符串是一个回文字符串. 要找出所有可能的组合. 办法:暴力搜索+回溯 class Solution { public: int *b,n; vector< ...

  3. [LeetCode] Palindrome Number 验证回文数字

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  4. LeetCode——Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...

  5. leetcode:Palindrome Number (判断数字是否回文串) 【面试算法题】

    题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...

  6. [Leetcode] Palindrome number 判断回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  7. [leetcode] Palindrome Number(不使用额外空间)

    本来推断回文串是一件非常easy的事情,仅仅须要反转字符串后在与原字符串相比較就可以.这道题目明白说明不能使用额外的空间.那么使用将其分解连接成字符串的方法便不是可行的.仅仅好採用数学的方式: 每次取 ...

  8. URAL 题目1297. Palindrome(后缀数组+RMQ求最长回文子串)

    1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The "U.S. Robots" HQ has just ...

  9. [LeetCode] 730. Count Different Palindromic Subsequences 计数不同的回文子序列的个数

    Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...

随机推荐

  1. Codeforces 1037F. Maximum Reduction

    总感觉我这种做法会T,一直没写,看了其他人的题解也是这样,,,就果断写了,,可能数据不太深,或者玄学复杂度 题意即求xk-1长度的所有区间的最大值的和,对每一个i(数组下边),他对答案的贡献数量就是在 ...

  2. Java多线程设计模式(4)线程池模式

    前序: Thread-Per-Message Pattern,是一种对于每个命令或请求,都分配一个线程,由这个线程执行工作.它将“委托消息的一端”和“执行消息的一端”用两个不同的线程来实现.该线程模式 ...

  3. 归档 & 解档

    代码实现 遵守协议 class AccessToken: NSObject, NSCoding 实现协议方法 // MARK: - 归档&解档 required init(coder aDec ...

  4. Mac如何通过远程控制其他Mac

    Mac如何通过远程控制其他Mac 发表于 2012 年 10 月 15 日 很多时候,我们会碰到需要被别人远程帮助或者远程帮助别人的情况,Windows下我们可以通过远程连接或者QQ远程协助来完成,但 ...

  5. linux之vim命令

    :tabe fn     在一个新的标签页中编辑文件fngt     切换到下一个标签页gT     切换到上一个标签页:tabr     切换到第一个标签页:tabl     切换到最后一个标签页: ...

  6. 【spring Boot】Spring中@Controller和@RestController之间的区别

    spring Boot入手的第一天,看到例子中的@RestController ............. 相同点:都是用来表示Spring某个类的是否可以接收HTTP请求 不同点:@Controll ...

  7. centos7 安装LNMP(php7)之php7.0 yum安装

    http://www.jianshu.com/p/35f21210668a 安装过程参考上面的网址

  8. flask的session解读及flask_login登录过程研究

    #!/usr/bin/env python # -*- coding: utf-8 -*- from itsdangerous import URLSafeTimedSerializer from f ...

  9. 41个linux命令大全(鸟哥的私房菜)

    转http://www.xmws.cn/show-87-419-1.html 41个linux命令大全 发布作者:微思网络   发布时间:2017-01-10   浏览量:709次 学过linux的人 ...

  10. 使用echarts简单制作中国地图,echarts中国地图

    网站需要一张中国地图,并且鼠标经过某个省份,该省份的省份名字显示,而且该省份的地区会变色显示. 第一种方法: 将每个省份的图片定位(先隐藏),拼合成一张中国地图,然后再定位省份名称,鼠标经过省份名字, ...