leetcode 9.回文数

class Solution {
    public boolean isPalindrome(int x) {
        Stack<Integer> stack = new Stack<>();
        int val;
        int mid = x;
        int compare;
        if (x < 0)
            return false;
        while (mid > 0) {
            val = mid % 10;
            stack.push(val);
            mid = mid / 10;
        }
        while (x > 0) {
            compare = x % 10;
            if (compare != stack.pop())
                return false;
            x = x / 10;
        }
        return true;
    }
}

你可能感兴趣的:(程序设计,leetcode)