LeetCode 9 Palindrome Number

时间:2022-06-23
本文章向大家介绍LeetCode 9 Palindrome Number,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

题目

c++

class Solution {
public:
    int a[100005];
    bool isPalindrome(int x) {
        
        if(x<0)
            return false;
        
        
        int pos=0;
        while(x)
        {
            a[pos++]=x%10;
            x/=10;
        }
        
        for(int i=0,j=pos-1;i<j;i++,j--)
        {
            if(a[i]!=a[j])
            {
                return false;
            }
        }
        
        return true;
        
    }
};