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]
posted @ 2019-04-25 16:36  benda  阅读(73)  评论(0编辑  收藏  举报