题目:

9. Palindrome Number

解答:

数字化为数字数组,然后验证首尾是否相同即可

class Solution {
public:
    bool isPalindrome(int x) {
        if(x < 0)   return false;
        vector<int> vec(32,0);
        int index = 0;
        while(x > 0){
            vec[index++] = x % 10;
            x /= 10;
        }
        for(int i = 0;i < index / 2; ++i){
            if(vec[i] != vec[index-1-i])
                return false;
        }
        return true;
    }
};

更新会同步在我的网站更新(https://zergzerg.cn/notes/webnotes/leetcode/index.html)

相关文章:

  • 2021-08-16
  • 2021-04-11
  • 2021-12-12
  • 2021-09-22
  • 2021-04-02
  • 2021-07-24
猜你喜欢
  • 2021-12-03
相关资源
相似解决方案