sweet1cris

Untitled

Feb 9th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1.  
  2. public class Solution {
  3.     /**
  4.      * @param num a positive number
  5.      * @return true if it's a palindrome or false
  6.      */
  7.     public boolean isPalindrome(int x) {
  8.         if(x < 0) {
  9.             return false;
  10.         }
  11.         return x == reverse(x);    
  12.     }
  13.    
  14.     public int reverse(int x) {
  15.         int rst = 0;
  16.         while(x != 0) {
  17.             rst = rst * 10 + x % 10;
  18.             x = x / 10;
  19.         }
  20.         return rst;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment