Palindrome Number

Palindrome Number

问题:

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

思路:

常用的进制遍历方法

while(num != 0)

{

        remian = num % 进制;

        num /= 进制;  

}
View Code

我的代码:

public class Solution {

    public boolean isPalindrome(int x) {

        if(x < 0)   return false;

        int reverse = reverse(x);

        return reverse == x;

    }

    public int reverse(int x)

    {

        int rst = 0;

        while(x != 0)

        {

            rst = rst * 10 + x % 10;

            x /= 10;

        }

        return rst;

    }

}
View Code

学习之处:

  • 常见数字访问方法,while(num != 0) num /= 进制数
  • 常用的进制增加方法, num = num * 进制 + some remain

你可能感兴趣的:(number)