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. django自定义signal的发送和接收样例

    想在项目中用上,就实习一下. # coding:utf8 from django.dispatch import Signal from django.dispatch import receiver ...

  2. EL的函数与标签

    1 什么EL函数库 EL函数库是由第三方对EL的扩展,我们现在学习的EL函数库是由JSTL添加的.下面我们会学习JSTL标签库. EL函数库就是定义一些有返回值的静态方法.然后通过EL语言来调用它们! ...

  3. 状压DP【p1879】[USACO06NOV]玉米田Corn Fields

    Description 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上 ...

  4. Cookie和Session在Node.JS中的实践(二)

    Cookie和Session在Node.JS中的实践(二) cookie篇在作者的上一篇文章Cookie和Session在Node.JS中的实践(一)已经是写得算是比较详细了,有兴趣可以翻看,这篇是s ...

  5. 微信小程序开发,上传wx.uploadFile 返回参数处理

    这真的是个坑,前端看了半天,说是字符串,让后台处理,后台说返回的是正确的,原来这个请求就是返回的string类型,见下图,无法取到code,需要前台自己转化. 以下为百度出来的参考: wx.reque ...

  6. ReactiveCocoa(二)

    前言 通过ReactiveCocoa(一)的学习,相信大家对ReactiveCocoa有了一些基本认识吧.下面就让我们来学习ReactiveCocoa的一些基本使用吧! ReactiveCocoa基本 ...

  7. Eclipse使用Debug模式调试Spring Boot项目时跳转到exitCurrentThread的问题

    Spring Boot项目使用了spring-boot-devtools工具且在Eclipse中Debug调试会自动跳转到这个方法: public static void exitCurrentThr ...

  8. form的action属性作用

    一.action=""和action="#".没有action属性的作用相同,都是提交到当前页面(也就是document.location.href) 二.ac ...

  9. oc的插件

    umbra https://umbra3d.com/ 很不错

  10. Spring Bean Life Cycle Methods – InitializingBean, DisposableBean, @PostConstruct, @PreDestroy and *Aware interfaces

    Spring Beans are the most important part of any Spring application. Spring ApplicationContext is res ...