题解 | #回文数字#

回文数字

http://www.nowcoder.com/practice/35b8166c135448c5a5ba2cff8d430c32

找到数的左边和右边,进行比较

初始化得到这个数是几位数

import java.util.*;
import java.math.*;

public class Solution {
    public boolean isPalindrome (int x) {
        // write code here
        if(x<0)return false;
        int max = 1;
        for(int i = x; i>9;i/=10)max*=10;
        
        while(x>9){
            if(x/max != x %10)return false;
            x = (x%max)/10;
            max /= 100;
        }
        return true;
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务