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 9.回文数
最新推荐文章于 2021-05-07 11:28:48 发布