leetcode在力扣 App 中打开
调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
困难
相关标签
相关企业
提示

给定一个表示整数的字符串 n ,返回与它最近的回文整数(不包括自身)。如果不止一个,返回较小的那个。

“最近的”定义为两个整数差的绝对值最小。

 

示例 1:

输入: n = "123"
输出: "121"

示例 2:

输入: n = "1"
输出: "0"
解释: 0 和 2是最近的回文,但我们返回最小的,也就是 0。

 

提示:

  • 1 <= n.length <= 18
  • n 只由数字组成
  • n 不含前导 0
  • n 代表在 [1, 1018 - 1] 范围内的整数
通过次数
26.7K
提交次数
88.2K
通过率
30.3%

相关标签

相关企业

提示 1
Will brute force work for this problem? Think of something else.

提示 2
Take some examples like 1234, 999,1000, etc and check their closest palindromes. How many different cases are possible?

提示 3
Do we have to consider only left half or right half of the string or both?

提示 4
Try to find the closest palindrome of these numbers- 12932, 99800, 12120. Did you observe something?


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
n =
"123"
Source