LeetCode: Palindrome Number
2013-09-29 09:28
337 查看
一般都需要用base来计数,排除数字中0的影响
class Solution {
public:
bool isPalindrome(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(x<0)
return false;
int base=1,right=0,left=x;
while(left>=base){
right = 10*right+left%10;
left /= 10;
base *= 10;
}
if(left==right||right/10==left)
return true;
return false;
}
};
class Solution {
public:
bool isPalindrome(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(x<0)
return false;
int base=1,right=0,left=x;
while(left>=base){
right = 10*right+left%10;
left /= 10;
base *= 10;
}
if(left==right||right/10==left)
return true;
return false;
}
};
相关文章推荐
- [LeetCode]Trapping Rain Water
- LeetCode(13) RomanToInteger
- Recover Binary Search Tree -- LeetCode
- leetcode 之 Two Sum 解题思路
- [LeetCode]Sort List
- leetcode[125] Valid Palindrome
- 83. Remove Duplicates from Sorted List Leetcode Python
- leetcode_36_validsudoku
- leetcode 第89题 Gray Code
- [LeetCode][Java] Jump Game
- Leetcode: Happy Number
- LeetCode-Valid Anagram
- LeetCode Longest Substring Without Repeating Characters
- [LeetCode 088] Merge Sorted Array
- leetcode 2 Add Two Numbers
- Leetcode 326. Power of Three
- LeetCode-233.Number of Digit One
- (LeetCode)Linked List Cycle --- 判断循环链表
- [leetcode] 438. Find All Anagrams in a String 解题报告
- Leetcode 90. Subsets II