- [回文] LeetCode9. Palindrome Numbe
- LeetCode 9. 回文数 Palindrome Numbe
- LeetCode9.回文数 JavaScript
- Leetcode9. Palindrome Number
- LeetCode #1147 Longest Chunked P
- LeetCode #267 Palindrome Permuta
- leetcode-9 Palindrome Number 回文
- LeetCode #1328 Break a Palindrom
- 每日算法之LeetCode 125:Valid Palindro
- PAT A 1136 1137 1138 1139

除以10以后,再构造一个newx,相等则是回文数
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0 || (x != 0 && x % 10 == 0)) //负数&结尾是0的数(不包括0),不是回文数
return false;
int newx = 0;
while(newx < x) { //少掉一半的循环
int re = x % 10;
x = x / 10;
newx = newx * 10 + re;
}
return ((x == newx) || (x == newx / 10)); //回文数有奇数长度和偶数长度两种情况
}
};
网友评论