Search

Imran Pollob
Imran Pollob
  • Home
  • Contact
  • Blog++
    Blog Data Structures & Algorithms Leetcode solution Hackerrank solution Codesignal solution
  • Light Dark
  • LEETCODE SOLUTIONS
  • 1920 - Build Array from Permutation
  • 1929 - Concatenation of Array
  • 1480 - Running Sum of 1d Array
  • 28 - Implement strStr()
  • 7 - Reverse Integer
  • 9 - Palindrome Number
  • 283 - Move Zeros
  • 485 - Max Consecutive Ones
  • Contents
  1. Home
  2. LEETCODE SOLUTIONS
  3. 9 - Palindrome Number

Leetcode 9 - Palindrome Number solution

Problem link

Solution:

class Solution {
    public boolean isPalindrome(int x) {
        if (x < 0){
            return false;
        }
        
        int rev = 0;
        int real = x;
            
        while (x != 0) {
            rev = rev * 10 + x % 10;
            x = (int) x / 10;
        }
        
        return rev == real;
        
    }
}
Previous
Leetcode 7 - Reverse Integer solution
Next
Leetcode 283 - Move Zeros solution

Last updated on Dec 20, 2021

© 2022 Imran Pollob

Published with Wowchemy — the free, open source website builder that empowers creators.

Cite
Copy Download