DSA · Math · #132
Palindrome Number
Module 58 · difficulty 2/5·⏱ 30:00starts on first keystroke
Given an integer `x`, return `true` if `x` is a palindrome, and `false` otherwise. An integer is a palindrome when it reads the same forward and backward. For example, `121` is a palindrome while `123` is not. Implement the function `isPalindrome(x)`. **Follow up:** Could you solve it without converting the integer to a string?
Examples
x = 121→true— Reads as 121 from left to right and from right to left.x = -121→false— From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.x = 10→false— Reads 01 from right to left. Therefore it is not a palindrome.
Constraints
- · -2^31 <= x <= 2^31 - 1
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.