java.lang.Object
g2301_2400.s2384_largest_palindromic_number.Solution

public class Solution extends Object
2384 - Largest Palindromic Number.<p>Medium</p> <p>You are given a string <code>num</code> consisting of digits only.</p> <p>Return <em>the <strong>largest palindromic</strong> integer (in the form of a string) that can be formed using digits taken from</em> <code>num</code>. It should not contain <strong>leading zeroes</strong>.</p> <p><strong>Notes:</strong></p> <ul> <li>You do <strong>not</strong> need to use all the digits of <code>num</code>, but you must use <strong>at least</strong> one digit.</li> <li>The digits can be reordered.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> num = &ldquo;444947137&rdquo;</p> <p><strong>Output:</strong> &ldquo;7449447&rdquo;</p> <p><strong>Explanation:</strong></p> <p>Use the digits &ldquo;4449477&rdquo; from &ldquo;<ins> <strong>44494</strong> </ins><ins> <strong>7</strong> </ins>13<ins> <strong>7</strong> </ins>&rdquo; to form the palindromic integer &ldquo;7449447&rdquo;.</p> <p>It can be shown that &ldquo;7449447&rdquo; is the largest palindromic integer that can be formed.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> num = &ldquo;00009&rdquo;</p> <p><strong>Output:</strong> &ldquo;9&rdquo;</p> <p><strong>Explanation:</strong></p> <p>It can be shown that &ldquo;9&rdquo; is the largest palindromic integer that can be formed.</p> <p>Note that the integer returned should not contain leading zeroes.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= num.length <= 10<sup>5</sup></code></li> <li><code>num</code> consists of digits.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • largestPalindromic

      public String largestPalindromic(String num)