Algorithm

LeetCode #9. Palindrome Number

2017-06-07  本文已影响0人  匠_心

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

Solution:

class Solution {
public:
    bool isPalindrome(int x) {
        string s = to_string(x);
        for(int i=0;i<s.size()/2;++i)
        {
            if(s[i]!=s[s.size()-i-1])
            {
                return false;
            }
        }
        return true;
    }
};
上一篇 下一篇

猜你喜欢

热点阅读