Leetcode 9回文数

class Solution {
public:
    bool isPalindrome(int x) {
        if(x<0)return false;
        if(x/10 == 0) return true;
        bool ans = false;
        
        int const_x =x;
        long y= 0;
        while(x != 0 )
        {
            if(y*10+x%10 > INT_MAX)
                return false;
            y=y*10+x%10;
            x=x/10;
            
        }
        
        
        if(const_x==y)ans=true;
        
        
        
        
        return ans;
    }
};

Leetcode 9回文数
倒序读数看两个是否一致就好了

相关文章:

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