![]() |
VOOZH | about |
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
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:
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:
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)