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

给你一个仅由数字(0 - 9)组成的字符串 num

请你找出能够使用 num 中数字形成的 最大回文 整数,并以字符串形式返回。该整数不含 前导零

注意:

  • 无需 使用 num 中的所有数字,但你必须使用 至少 一个数字。
  • 数字可以重新排序。

 

示例 1:

输入:num = "444947137"
输出:"7449447"
解释:
从 "444947137" 中选用数字 "4449477",可以形成回文整数 "7449447" 。
可以证明 "7449447" 是能够形成的最大回文整数。

示例 2:

输入:num = "00009"
输出:"9"
解释:
可以证明 "9" 能够形成的最大回文整数。
注意返回的整数不应含前导零。

 

提示:

  • 1 <= num.length <= 105
  • num 由数字(0 - 9)组成
通过次数
13K
提交次数
39.5K
通过率
32.9%


相关企业

提示 1
In order to form a valid palindrome, other than the middle digit in an odd-length palindrome, every digit needs to exist on both sides.

提示 2
A longer palindrome implies a larger valued palindrome. For palindromes of the same length, the larger digits should occur first.

提示 3
We can count the occurrences of each digit and build the palindrome starting from the ends. Starting from the larger digits, if there are still at least 2 occurrences of a digit, we can place these digits on each side.

提示 4
Make sure to consider the special case for the center digit (if any) and zeroes. There should not be leading zeroes.

相似题目

评论 (0)

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