← 返回 roblox 的题目列表Find the Closest Palindrome (LeetCode 564)
类型:qbank
Given an integer string, find the nearest different integer that is a palindrome.
Examples
Example 1:
Input: n = "123"
Output: "121"
Explanation:
Both 121 and 131 differ from 123 by 2; the smaller wins.
Example 2:
Input: n = "1"
Output: "0"
Explanation:
0 and 2 are both 1 away from 1; return the smaller (0).
Constraints
1 <= n.length <= 18
n consists of digits only.
n does not have leading zeros.
n is representing an integer in the range [1, 10^18 - 1].