码迷,mamicode.com
首页 > 其他好文 > 详细

【Leetcode】Palindrome Number

时间:2016-06-12 03:26:28      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: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
 技术分享技术分享
  1. public boolean isPalindrome(int x) {  
  2.     String s = String.valueOf(x);  
  3.     for(int i=0;i<s.length()/2;i++){  
  4.         if(s.charAt(i)!=s.charAt(s.length()-1-i))  
  5.             return false;  
  6.     }  
  7.     return true;  
  8. }  


【Leetcode】Palindrome Number

标签:

原文地址:http://blog.csdn.net/yeqiuzs/article/details/51598089

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!