[LeetCode]Palindrome Number 推断二进制和十进制是否为回文
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 推断二进制和十进制是否为回文的更多相关文章
- 9. Palindrome Number(判断整型数字是否是回文,直接暴力即可)
Determine whether an integer is a palindrome. Do this without extra space. class Solution: def isPal ...
- [LeetCode]Palindrome Partitioning 找出所有可能的组合回文
给定一个字符串,切割字符串,这样每个子字符串是一个回文字符串. 要找出所有可能的组合. 办法:暴力搜索+回溯 class Solution { public: int *b,n; vector< ...
- [LeetCode] Palindrome Number 验证回文数字
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- LeetCode——Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- leetcode:Palindrome Number (判断数字是否回文串) 【面试算法题】
题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...
- [Leetcode] Palindrome number 判断回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- [leetcode] Palindrome Number(不使用额外空间)
本来推断回文串是一件非常easy的事情,仅仅须要反转字符串后在与原字符串相比較就可以.这道题目明白说明不能使用额外的空间.那么使用将其分解连接成字符串的方法便不是可行的.仅仅好採用数学的方式: 每次取 ...
- URAL 题目1297. Palindrome(后缀数组+RMQ求最长回文子串)
1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The "U.S. Robots" HQ has just ...
- [LeetCode] 730. Count Different Palindromic Subsequences 计数不同的回文子序列的个数
Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...
随机推荐
- AC日记——Dining poj 3281
[POJ-3281] 思路: 把牛拆点: s向食物连边,流量1: 饮料向t连边,流量1: 食物向牛1连边,流量1: 牛2向饮料连边,流量1: 最大流: 来,上代码: #include <cstd ...
- iOS 代理 重定向消息 forwardInvocation
今天简单研究一下iOS的重定向消息forwardInvocation: 首先看看Invocation类: @interface NSInvocation : NSObject { @private _ ...
- c#作业(2班)
第二章 1.编写一个控制台程序,要求: 接受从控制台输入的姓名,如:张三 程序响应:你好,张三. 在代码中使用规范的注释,说明程序的功能 编译程序,并执行. 程序执行效果如下图: using Syst ...
- Java多线程设计模式(4)线程池模式
前序: Thread-Per-Message Pattern,是一种对于每个命令或请求,都分配一个线程,由这个线程执行工作.它将“委托消息的一端”和“执行消息的一端”用两个不同的线程来实现.该线程模式 ...
- Tomcat部署多个应用时日志文件路径相同引起的问题
今天给客户部署新系统,一个 前台应用,一个后台应用,由于用的是同一个架子,日志文件路径也没改,所以两个应用的日志文件是同一个文件,这样应用运行时,就会出现只能访问一个应用的情况,如果两个应用同时访问, ...
- Java算法题:求素数
题目:判断101-200之间有多少个素数,并输出所有素数. 思路:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数. 具体代码: public Ve ...
- Linux下系统信息工具之Saidar
Saidar,是一款命令行下的小工具,可用来查看CPU.进程.负载.内存.交换分区.网络.磁盘.文件系统等系统信息. #ubuntu sudo apt-get install saidar -y #f ...
- EF使用延迟加载的本质原因
EF(Entity Framework)是微软的一个ORM框架 使用过EF的同学都知道它有一个延迟加载的功能 那么这个延迟加载的功能到底是什么? 为什么需要延迟加载? 使用延迟加载的优点和缺点又各是什 ...
- Linux SSH和SFTP服务分离
Linux SSH和SFTP服务分离 学习了:https://www.cnblogs.com/zihanxing/articles/5665383.html 都是监听22端口:
- 转: java语法与ide级入门介绍 from: IBM dev
点评: 讲的比较初级,但是有教你使用ide (Eclipse) frrom:http://www.ibm.com/developerworks/java/tutorials/j-introtojava ...