[LeetCode] 9 - Palindrome Number
2015-08-28 11:05
190 查看
Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0) {
return false;
}
if(x < 10) {
return true;
}
int base0 = 1;
int base1 = 1;
int x1 = x;
while (x1 >= 10) {
x1 /= 10;
base1 *= 10;
}
while (base1 > base0) {
int low = (x / base0) % 10;
int high = (x / base1) % 10;
if (low != high) {
return false;
}
base0 *= 10;
base1 /= 10;
}
return true;
}
};
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0) {
return false;
}
if(x < 10) {
return true;
}
int base0 = 1;
int base1 = 1;
int x1 = x;
while (x1 >= 10) {
x1 /= 10;
base1 *= 10;
}
while (base1 > base0) {
int low = (x / base0) % 10;
int high = (x / base1) % 10;
if (low != high) {
return false;
}
base0 *= 10;
base1 /= 10;
}
return true;
}
};
相关文章推荐
- android中activity,window,view之间的关系
- js实现显示当前状态的导航效果代码
- 完全背包——方案个数 UVA11137 Ingenuous Cubrency
- Maven介绍
- C语言中操作密码文件的一些函数总结
- 服务器tcp连接timewait过多优化及详细分析
- 说说微信支付那点事
- 图像分割之(一)概述
- Lua中的九九乘法表以及字符串拼接
- c++中的rand函数
- Mac环境下svn的使用
- 人生职业规划
- DNS从服务器迁移(基于windows为主,linux为从实现同步)
- 类模板Template
- ActiveMQ 即时通讯服务 浅析
- 网络编程socket accept函数的理解
- Android性能优化之使用SparseArray代替HashMap
- BaseServlet<学习随笔>
- 使用HttpClient上传文件资源(已验证)
- 生活中的状态模式