about // doc

LeetCode - Palindrome Number

Click here to go back to LeetCode summary page.

Problem description is here, or as follows:

Determine whether an integer is a palindrome. 
Do this without extra space.

First of all, according to Wikipedia’s definition, “a palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward”.

In Solution 1, the length of the integer is first determined, and then the comparison of digits starts from two ends and progresses toward the middle. This solution uses division operator “/” and modulo operator “%” extensively. The solution uses constant space, and the run-time complexity is O(N).

Solution 2 uses the same idea but implements the code a little differently (it manipulates the divisor rather than the number itself in Solution 1).

Although the algorithm is somewhat mundane, this type of problem needs practice.

comments powered by Disqus