|
| 1 | +<h2><a href="https://leetcode.com/problems/find-the-closest-palindrome">564. Find the Closest Palindrome</a></h2><h3>Hard</h3><hr><p>Given a string <code>n</code> representing an integer, return <em>the closest integer (not including itself), which is a palindrome</em>. If there is a tie, return <em><strong>the smaller one</strong></em>.</p> |
| 2 | + |
| 3 | +<p>The closest is defined as the absolute difference minimized between two integers.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> n = "123" |
| 10 | +<strong>Output:</strong> "121" |
| 11 | +</pre> |
| 12 | + |
| 13 | +<p><strong class="example">Example 2:</strong></p> |
| 14 | + |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> n = "1" |
| 17 | +<strong>Output:</strong> "0" |
| 18 | +<strong>Explanation:</strong> 0 and 2 are the closest palindromes but we return the smallest which is 0. |
| 19 | +</pre> |
| 20 | + |
| 21 | +<p> </p> |
| 22 | +<p><strong>Constraints:</strong></p> |
| 23 | + |
| 24 | +<ul> |
| 25 | + <li><code>1 <= n.length <= 18</code></li> |
| 26 | + <li><code>n</code> consists of only digits.</li> |
| 27 | + <li><code>n</code> does not have leading zeros.</li> |
| 28 | + <li><code>n</code> is representing an integer in the range <code>[1, 10<sup>18</sup> - 1]</code>.</li> |
| 29 | +</ul> |
0 commit comments