2020-9-3
经典题目却一波三折,提交的时候忽略了负数的样例,偷懒用了string和stl,只是逐位把数字加入到字符串中。
https://leetcode-cn.com/problems/palindrome-number/
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0)
return false;
string s1 = "";
while(x)
{
s1.push_back(x%10 + '0');
x /= 10;
}
string s2 = s1;
reverse(s1.begin(),s1.end());
return s1 == s2;
}
};