java.lang.Object
g2301_2400.s2384_largest_palindromic_number.Solution

public class Solution extends Object
2384 - Largest Palindromic Number.

Medium

You are given a string num consisting of digits only.

Return the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes.

Notes:

  • You do not need to use all the digits of num, but you must use at least one digit.
  • The digits can be reordered.

Example 1:

Input: num = โ€œ444947137โ€

Output: โ€œ7449447โ€

Explanation:

Use the digits โ€œ4449477โ€ from โ€œ 44494 7 13 7 โ€ to form the palindromic integer โ€œ7449447โ€.

It can be shown that โ€œ7449447โ€ is the largest palindromic integer that can be formed.

Example 2:

Input: num = โ€œ00009โ€

Output: โ€œ9โ€

Explanation:

It can be shown that โ€œ9โ€ is the largest palindromic integer that can be formed.

Note that the integer returned should not contain leading zeroes.

Constraints:

  • 1 <= num.length <= 105
  • num consists of digits.
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • largestPalindromic

      public String largestPalindromic(String num)