Leetcode 9. Palindrome Number
https://leetcode.com/problems/palindrome-number/
class Solution {
public:
bool isPalindrome(int x) {
using namespace std;
if(x<0) return false;
string s=to_string(x);
int l=0,r=s.size()-1;
while(l<r){
if(s[l]!=s[r]) return false;
++l,--r;
}
return true;
}
};
python版本
class Solution:
def isPalindrome(self, x: int) -> bool:
x=str(x)
return x==x[::-1]