VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-check-the-number-is-palindrome-or-not/

⇱ Program to check the number is Palindrome or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to check the number is Palindrome or not

Last Updated : 11 Jul, 2025

Given an integer N, write a program that returns true if the given number is a palindrome, else return false. 
Examples:

Input: N = 2002 
Output: true
Input: N = 1234
Output: false


👁 Image



Approach:
A simple method for this problem is to first reverse digits of n, then compare the reverse of n with n. If both are same, then return true, else false.
Below is the implementation of the above approach: 


Output
Is 4562 a Palindrome number? -> false
Is 2002 a Palindrome number? -> true

Time Complexity: O(logN) 
Auxiliary Space: O(1)

Another Approach: 
First , convert that number to strin and check if the reverse of that string equal to original string

Below is the implementation of the above approach:


Output
Is 4562 a Palindrome number? : NO
Is 2002 a Palindrome number? : Yes

Time Complexity: O(m) where m is the length of the number in string format
Auxiliary Space: O(m)

Comment
Article Tags: