LeetCode-9 Palindrome Number

来源:互联网 发布:mysql 视频 编辑:程序博客网 时间:2024/05/20 18:19
一、题目描述:
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;        else if(x==0)            return true;        else{            int temp=x;            int pal=0;            while(x!=0){                pal=pal*10+x%10;                x=x/10;            }            if(temp==pal)                return true;            else                return false;        }            }}

0 0
原创粉丝点击