【Leetcode】Palindrome Number
2016-06-06 20:38
218 查看
题目链接:https://leetcode.com/problems/palindrome-number/
题目:
Determine whether an integer is a palindrome. Do this without extra space.
Some hints:
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
There is a more generic way of solving this problem.
思路:
easy
算法:
[java] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
public boolean isPalindrome(int x) {
String s = String.valueOf(x);
for(int i=0;i<s.length()/2;i++){
if(s.charAt(i)!=s.charAt(s.length()-1-i))
return false;
}
return true;
}
题目:
Determine whether an integer is a palindrome. Do this without extra space.
Some hints:
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
There is a more generic way of solving this problem.
思路:
easy
算法:
[java] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
public boolean isPalindrome(int x) {
String s = String.valueOf(x);
for(int i=0;i<s.length()/2;i++){
if(s.charAt(i)!=s.charAt(s.length()-1-i))
return false;
}
return true;
}
相关文章推荐
- 【Leetcode】Rectangle Area
- 2016NEFU集训第n+3场 E - New Reform
- 储存班长的学生类信息
- ecstore后台finder的取数据流程
- PHP 开发学习[3] —— 文字水印,缩略图,图片水印实现类
- 算法导论第八章-线性时间排序-Cpp代码实现
- 动态加载Dex的原理
- 【Leetcode】Add Binary
- 博文列表中博文浏览次数回显功能
- 6月5日 smarty变量调节器 函数 配置文件
- windows多线程编程
- 网页微信配合谷歌浏览器实现自动发送信息
- 骨牌覆盖问题 KxM
- 骨牌覆盖问题 KxM
- Sass与Compress实战:第六章
- php缓冲区与header函数之间的秘密
- event-button:鼠标按钮
- POJ 1456 Supermarket【贪心+并查集】
- 【Leetcode】Reverse Integer
- Going Deeper with Convolutions