[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 ...
随机推荐
- (9)oracle 表的基本查询
转到进阶查询 查看表的结构 desc 表名; desc student; 查看整张表的数据 select * from 表名; //查整张表很耗时间 select* from student; 查看 ...
- Cookie和Session在Node.JS中的实践(二)
Cookie和Session在Node.JS中的实践(二) cookie篇在作者的上一篇文章Cookie和Session在Node.JS中的实践(一)已经是写得算是比较详细了,有兴趣可以翻看,这篇是s ...
- 数值计算方法 | C语言实现几个数值计算方法(实验报告版)
目录 写在前面 实验一 牛顿插值方法的实现 实验二 龙贝格求积算法的实现 实验三 高斯列主元消去法的实现 实验四 最小二乘方法的实现 写在前面 使用教材:<数值计算方法>黄云清等编著 科学 ...
- android RelativeLayout控件或view实现叠加效果
在开发android程序的时候,我们经常会遇到让控件或是view实现叠加的效果,一般这种情况,很多人会使用Framelayout来处理,可是有一个问题Framelayout布局在布局上会有很多限制,不 ...
- MySQL 5.7.17 Group Replication 初始
http://blog.csdn.net/mchdba/article/details/53957248
- 【转】Cvmat与IplImage的相互转换
seyvlei 原文地址 1.IplImage转Cvmat IplImage* src = cvLoadImage(); CvMat* mat=cvCreateMat(src->height,s ...
- zabbix agent被动模式配置
zabbix agent检测分为主动(agent active)和被动(agent)两种形式,主动与被动的说法均是相对于agent来讨论的.简单说明一下主动与被动的区别如下: 主动:agent请求se ...
- iOS uitableivewCell 下划线顶格
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath ...
- left menu
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SQLite升级数据库:
SQLiteOpenHelper子类关键代码: SQLite升级数据库: SQLiteOpenHelper子类关键代码: public class MyDataHelper extends SQLit ...