LeetCode Palindrome Number
2015-06-01 09:36
253 查看
Description:
Determine whether an integer is a palindrome. Do this without extra space.
Solution:
Since it is required that no extra space is used, so we only have to take out the corresponding left and right digit of a number
respectively, and make comparison between them.
Determine whether an integer is a palindrome. Do this without extra space.
Solution:
Since it is required that no extra space is used, so we only have to take out the corresponding left and right digit of a number
respectively, and make comparison between them.
public class Solution { public boolean isPalindrome(int x) { if (x < 0) return false; int bigger = 1, smaller = 1; for (int i = 1; i < (x + "").length(); i++) bigger = bigger * 10; while (bigger >= smaller) { if (x / bigger % 10 != x / smaller % 10) { // System.out.println(x / bigger % 10); return false; } bigger = bigger / 10; smaller = smaller * 10; } return true; } public static void main(String[] args) { Solution solution = new Solution(); solution.isPalindrome(12321); } }
相关文章推荐
- GestureDetector和SimpleOnGestureListener的使用教程
- XCode快捷键
- android:layout_weight属性详解 (转)
- ios之清除cell缓存,解决cell的重用问题。
- 018_01图片特效
- 定时打开浏览器
- linux top命令详解
- 影响HBase insert性能的几个因素
- 历遍文件夹
- [win7] 带网络的安全模式,启动QQEIMPlatform第三方服务
- SqlServer新建视图
- spring aop 实现方法执行时间监控
- C#--WEb中登录时输入各项的验证
- DDoS
- android view.requestLayout()方法
- NYOJ 102次方求模(快速幂)
- bootm命令中地址参数,内核加载地址以及内核入口地址
- 刚开通,发布第一篇文章!!
- oracle 分库分表(sharding)
- 遍历Map的四种方法