9. Palindrome Number(回文数)C++

将int转换为string,注意for循环判断条件的简化

class Solution {
public:
    bool isPalindrome(int x) {
        if(x < 0)
            return false;
        string s = to_string(x);
        int si = s.size();
        for(int i=0; i<si/2;i++)
        {
            if(s.at(i) != s.at(si-i-1))
            {
                return false;
            }
        }
        return true;
        
    }
};

原文地址:https://www.cnblogs.com/tornado549/p/9942328.html