C++ solution: transfer to string (AC)


  • 0
    P

    This is my solution

    class Solution {
    public:
        bool isPalindrome(int x) {
            if(x<0) return false;
            string a = ""+to_string(x); bool bo = true;
            
            for(int i = 0; i< (a.length()+1)/2; ++i){
                if(a[i] != a[a.length() -1 -i]) {bo = false; break;}
            }
            return bo;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.