LeetCode 0009 - Palindrome Number

2021-08-11 10:18:52 浏览数 (2)

Palindrome Number

Desicription

Determine whether an integer is a palindrome. Do this without extra space.

Solution

代码语言:javascript复制
class Solution {
public:
    bool isPalindrome(int x) {
        stringstream stream;
        string res;
        stream << x;
        stream >> res;
        for(int i = 0, j = res.size()-1; i <= j; i  , j--){
            if(res[i] != res[j])
                return 0;
        }        
        return 1;
    }
};

0 人点赞