Leetcode 564: Find the closest palindrome
We are given a number n. On the number line, there are infinite numbers on the right of n and left of n that are palindromes. The question is asking us to find a number that is a palindrome and has the minimum distance from n on the number line. We break the problem into 2 parts: find the next element on the number line after n that is a palindrome. find the previous element on the number line before n that is a palindrome. Suppose i and j are numbers such that i < n < j and i and j are both palindromes. And i and j are the nearest numbers to n on the number line We just find which of i and j is the nearer one to n on the number line and return it The simplest way of doing this is: ...