题目大意:
判断是否是个回文数
思路:
把数字转换成字符串,通过reverse来判断和原来是否相等。
代码:
class Solution {
public:
bool isPalindrome(int x) {
string s=to_string(x);
string s1=s;
reverse(s.begin(),s.end());
if(s==s1) return true;
return false;
}
};
tips:
- reverse()函数的运用:reverse(s.begin(),s.end()),这个是个返回类型为void的函数。
- to_string(x)是个返回类型为string的函数。