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. Delphi存取图像完整解决方案

    http://blog.sina.com.cn/s/blog_693cf1cf0100plkq.html 对于涉及图像数据的数据库应用程序,图像数据的存取技术是一个关键.由于缺少技术文档及DEMO例程 ...

  2. 模板—字符串—AC自动机(多模式串,单文本串)

    模板—字符串—AC自动机(多模式串,单文本串) Code: #include <queue> #include <cstdio> #include <cstring> ...

  3. PowerDisginer中NAME与COMMENT转换脚本

    Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl ' the current model ' get t ...

  4. 写了一个远程桌面管理的Visual Studio扩展程序

    最近看了写Visual Studio扩展相关的一些资料,周末写了一个远程桌面管理器的扩展程序来练练手,由于和VisualStudio集成了,无需切换窗口,用起来还是觉得挺方便的. 关于远程桌面管理器的 ...

  5. VisualStudio Shell简介 — 集成插件

    Visual Studio Shell只是提供了一个内核,我们还需要在其基础上补充功能,从而实现我们自己的IDE.Visual Studio Shell的插件开发和Visual Studio插件开发是 ...

  6. 利用osql/ocmd批处理批量执行sql文件

    原文:利用osql/ocmd批处理批量执行sql文件 上周在测试环境建了几十张表,保存了.sql文件,准备在正式环境重建的时候懒得一个个打开建了,做一在网上搜寻了一下,果然有简单点的方法. 利用osq ...

  7. SQL的连接(外连接、内连接、交叉连接和自连接)

    在查询多个表时,我们经常会用到连接查询,连接是关系型数据库的主要特点,也是它区别于其他类型的数据库管理系统的一个标志. 一.什么是连接查询 连接查询:根据两个表或者多个表的列之间的关系,来从这些表中查 ...

  8. 【Linux】CentOS7上rpm命令批量卸载删除模糊rpm包名

    例如,我要删除如下文件名匹配上wine的所有文件

  9. 为什么我不使用Kubernetes的Ingress

    为什么我不使用Kubernetes的Ingress 很不幸,据我所知Kubernetes的文档不是很完美,这就是为什么有很多同学在使用它的时候会遇到很多的坑,Ingress这个组件就是这些坑中的一个. ...

  10. 损失函数(loss function)

    通常而言,损失函数由损失项(loss term)和正则项(regularization term)组成.发现一份不错的介绍资料: http://www.ics.uci.edu/~dramanan/te ...