题目链接

【题解】

还是要注意,取反的时候,-2^31 取反的话会爆掉Int。。(因为int的正数最多到2^31-1)

【代码】

class Solution {
    public:           
    bool isPalindrome(int x) {
        int f = -1;
        string s;
        s = "";
        if (x<0) {
            s+="-";
            f = 1;
        }
        while (f*x<0){
            char key = (x%10)+'0';
            s = key+s;
            x/=10;
        }
        string ts = s;
        reverse(ts.begin(),ts.end());
        if (ts==s)
            return true;
        else return false;
    }

};

相关文章:

  • 2022-12-23
  • 2021-05-18
  • 2022-02-14
  • 2021-12-01
  • 2021-08-08
  • 2021-10-30
  • 2021-06-24
猜你喜欢
  • 2021-01-29
  • 2022-01-13
  • 2021-10-18
  • 2021-04-17
  • 2021-07-28
  • 2021-12-19
  • 2021-12-31
  • 2022-12-23
相关资源
相似解决方案