问题来源:https://leetcode.com/problems/palindrome-number/
问题描述:Determine whether an integer is a palindrome. Do this without extra space.
我的代码:问题较简单,解决方案较多,直接上代码:
bool isPalindrome(int x){
//利用stringstream进行int转string
/*stringstream s;
s << x;
string temp = s.str();*/
//调用to_string直接转换 速度较快
string temp = std::to_string(x);
//手动判断
for (int i = 0; i < temp.size()/2; i++){
if (temp[i] != temp[temp.size() - 1 - i])
return false;
}
return true;
//调用reverse函数判断是否相等
/*reverse(temp.begin(), temp.end());
if (temp == s.str())
return true;
else{
return false;
}*/
}