My 69 ms C++ solution


  • 0
    Y

    class Solution {
    public:
    bool isPalindrome(int x) {
    if(x<0) return false;
    if(x<10) return true;
    if(x%10==0) return false;
    string str = to_string(x);
    int i=0;
    int j=str.size()-1;
    while(i<j)
    {
    if(str[i]!=str[j])
    return false;
    i++;
    j--;
    }
    return true;
    }
    };


Log in to reply
 

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