9. Palindrome Number

来源:互联网 发布:android 内存管理源码 编辑:程序博客网 时间:2024/06/08 17:36

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;        }        int n = x;        int res = 0;        while (x > 0) {            res = res * 10 + x % 10;            x /= 10;        }        return res == n;    }}
public static  boolean isPalindrome(int x) {        try {            if(x<0){                return false;            }            String s = x+"";            String res = "";            for(int i = s.length()-1;i>=0;i--){                res += s.charAt(i);            }            if(res.equals(s)){                return true;            }else{                return false;            }        } catch (Exception e) {            // TODO Auto-generated catch block            return false;        }
0 0
原创粉丝点击