#include "pch.h"
#include<vector>
#include<string>
#include<iostream>
using namespace std;
#include<algorithm>
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0)
{
return false;
}
long reverse = 0;//这要用long 防止溢出
int temp;
int ori_x = x;
while (ori_x > 0)
{
temp = ori_x % 10;
ori_x /= 10;
reverse = reverse * 10 + temp;
}
if (reverse == x)
{
return true;
}
else {
return false;
}
}
};
int main()
{
Solution sol;
bool i=sol.isPalindrome(121);
cout << i << endl;
}
力扣9
最新推荐文章于 2024-05-15 08:56:16 发布