【Leetcode Algorithm】Palindrome Number
2015-07-02 15:17
477 查看
Determine whether an integer is a palindrome. Do this withoutextra space.代码:
123456789101112131415161718192021222324252627 | public class Solution { public boolean isPalindrome( int x) { //负数不是回文数字 if (x< 0 ){ return false ; } //0是回文数字 else if (x== 0 ){ return true ; } //如果x为正数 else { int tmpx = x; int newx = 0 ; //翻转x while (tmpx> 0 ){ newx = newx* 10 + (tmpx% 10 ); tmpx = tmpx/ 10 ; } //判断翻转后的newx和x是否相同 if (newx==x){ return true ; } return false ; } } } |
相关文章推荐
- leetcode 179 Largest Number
- leetcode 24 Swap Nodes in Pairs
- leetcode 2 Add Two Numbers 方法1
- leetcode 2 Add Two Numbers 方法2
- [LeetCode]47 Permutations II
- [LeetCode]65 Valid Number
- [LeetCode]123 Best Time to Buy and Sell Stock III
- [LeetCode] String Reorder Distance Apart
- [LeetCode] Sliding Window Maximum
- [LeetCode] Find the k-th Smallest Element in the Union of Two Sorted Arrays
- [LeetCode] Determine If Two Rectangles Overlap
- [LeetCode] A Distance Maximizing Problem
- LeetCode[Day 1] Two Sum 题解
- LeetCode[Day 2] Median of Two Sorted Arrays 题解
- LeetCode[Day 3] Longest Substring Without... 题解
- LeetCode [Day 4] Add Two Numbers 题解
- LeetCode [Day 5] Longest Palindromic Substring 题解
- LeetCode [Day 6] ZigZag Conversion 题解
- LeetCode 2: Add Two Numbers (JAVA)
- LeetCode 1: Two Sum (JAVA)