C++ code by converting to a string

  • 0
        bool isPalindrome(int x) {
            string s = to_string(x);
            int len = s.length();
            if(len == 1)
                return true;
            for(int i=0; i<len/2; i++) 
                if(s[i] != s[len-1-i])
                    return false;
            return true;```

Log in to reply

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