Palindrome Number
The problem
You are given an integer n. You need to check whether the number is a **palindrome **number or not. Return **true **if it's a **palindrome **number, otherwise return false.
A **palindrome **number is a number which reads the **same **both left to right and right to left.
Input: n = 121 Output: true Explanation: When read from left to right : 121. When read from right to left : 121.
Input: n = 123 Output: false Explanation: When read from left to right : 123. When read from right to left : 321.
Input: 101
- 0 <= n <= 5000
- n will contain no leading zeroes except when it is 0 itself.
cpp
class Solution {
public:
bool isPalindrome(int n) {
}
};java
class Solution {
public boolean isPalindrome(int n) {
}
}python
class Solution:
def isPalindrome(self, n):javascript
class Solution {
isPalindrome(n) {
}
}csharp
public class Solution
{
public bool IsPalindrome(int n)
{
}
}go
func isPalindrome(n int) bool {
}Stuck? Show a way to structure it+
- 01Reject negative inputs if the domain includes them.
- 02Reverse either all digits or only the second half.
- 03Compare the original with the reversed representation.
- 04Handle trailing zeroes correctly.
Reference answer
Then expect these follow-ups
How would you test palindrome without converting to a string?
Tests: numeric manipulation
How would you check a linked-list palindrome?
Tests: list algorithms
Hiring now
Get the Infosys interview, not just the prep
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Next question