[Leetcode] 9. Palindrome Number

来源:互联网 发布:淘宝卖iphone靠谱的店 编辑:程序博客网 时间:2024/05/16 06:57

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

public class Solution {    public boolean isPalindrome(int x) {        if(x < 0) return false;        if(x / 10 == 0) return true;        int reverse = 0;        int num = x;        while(x != 0){            reverse = reverse * 10 + x % 10;            x /= 10;        }        return reverse == num;    }}


0 0
原创粉丝点击