Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- /**
- * @param num a positive number
- * @return true if it's a palindrome or false
- */
- public boolean isPalindrome(int x) {
- if(x < 0) {
- return false;
- }
- return x == reverse(x);
- }
- public int reverse(int x) {
- int rst = 0;
- while(x != 0) {
- rst = rst * 10 + x % 10;
- x = x / 10;
- }
- return rst;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment