LeetCode source
The challenge with this problem is that you're not allowed to use any string. You have to take the integer and come up with a solution that doesn't employ string or any of its methods. From the first glance, what was apparent is that we'll need a data structure to hold the individual integers for comparison.
Details of the the algorithm for the solution is as follows:
- If it's a single digit, then it's a Palindrome Number.
- Ignore any negative integers.
- For all other types of integers, pop each digit and store them in a vector in order.
- Compare the
(n + i)thinteger with(vector.size() - 1 - i)thinteger. - If this comparisos fails (i.e.
comparison == false) return false. - Else continue the comparisons until
ireaches the middle of the vector. If nofalsewas return before, it means all the comparisons weretrueand therefore, the integer is a palindrome.
- Time Complexity:
// TODO - Space Complexity:
// TODO
11509 / 11509 test cases passed
| Status | Runtime | Memory |
|---|---|---|
| Accepted | 36 ms | 11.7 MB |