Tap here to switch tabs
Problem
Submissions

Problem: Find the Closest Palindrome

Try to solve the Find the Closest Palindrome problem.

Statement

Given a string n representing an integer, return the closest palindromic integer represented as a string, excluding n itself.

The distance between two integers is defined as the absolute difference between their numeric values. If there are multiple palindromic integers with the same minimal absolute difference to n, return the numerically smaller one.

Constraints:

  • 1≤1 \leq n.length ≤18\leq 18

  • n consists of only digits.

  • n does not have leading zeros.

  • n represents an integer in the range [1,1018−1][1, 10^{18} - 1].

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Closest Palindrome

Try to solve the Find the Closest Palindrome problem.

Statement

Given a string n representing an integer, return the closest palindromic integer represented as a string, excluding n itself.

The distance between two integers is defined as the absolute difference between their numeric values. If there are multiple palindromic integers with the same minimal absolute difference to n, return the numerically smaller one.

Constraints:

  • 1≤1 \leq n.length ≤18\leq 18

  • n consists of only digits.

  • n does not have leading zeros.

  • n represents an integer in the range [1,1018−1][1, 10^{18} - 1].