Leetcode Week6

来源:互联网 发布:儿童桌面软件 编辑:程序博客网 时间:2024/05/16 07:11
/*
4.判断整数是否是回文(Determine whether an integer is a palindrome. Do this without extra space.)
,即从前面往后面读与从后面往前面读是一样的,例:12321;
*/


/*
class Solution {
public:
    bool isPalindrome(int x) {
        if(x<0){
            return 0;
        }else if(x==0){
            return 1;
        }
        
        if(x == reverse(x)){
            return 1;
        }else{
            return 0;
        }
    }
    
    int reverse(int x){
        int res=0;
        while(x>0){
            res = res*10 + x%10;
            x /= 10;
        }
        return res;
    }
};
*/
0 0